dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; public class Node { public int data ; public Node next ; public Node ( int key ) { data = key ; next = null ; } } public class GFG { static Node head ; static void printList ( Node node ) { while ( node != null ) { Console . Write ( node . data + " ▁ " ) ; node = node . next ; } Console . WriteLine ( ) ; } static Node mergeKLists ( Node [ ] arr , int last ) { for ( int i = 1 ; i <= last ; i ++ ) { while ( true ) { Node head_0 = arr [ 0 ] ; Node head_i = arr [ i ] ; if ( head_i == null ) break ; if ( head_0 . data >= head_i . data ) { arr [ i ] = head_i . next ; head_i . next = head_0 ; arr [ 0 ] = head_i ; } else { while ( head_0 . next != null ) { if ( head_0 . next . data >= head_i . data ) { arr [ i ] = head_i . next ; head_i . next = head_0 . next ; head_0 . next = head_i ; break ; } head_0 = head_0 . next ; if ( head_0 . next == null ) { arr [ i ] = head_i . next ; head_i . next = null ; head_0 . next = head_i ; head_0 . next . next = null ; break ; } } } } } return arr [ 0 ] ; } static public void Main ( ) { int k = 3 ; Node [ ] arr = new Node [ k ] ; arr [ 0 ] = new Node ( 1 ) ; arr [ 0 ] . next = new Node ( 3 ) ; arr [ 0 ] . next . next = new Node ( 5 ) ; arr [ 0 ] . next . next . next = new Node ( 7 ) ; arr [ 1 ] = new Node ( 2 ) ; arr [ 1 ] . next = new Node ( 4 ) ; arr [ 1 ] . next . next = new Node ( 6 ) ; arr [ 1 ] . next . next . next = new Node ( 8 ) ; arr [ 2 ] = new Node ( 0 ) ; arr [ 2 ] . next = new Node ( 9 ) ; arr [ 2 ] . next . next = new Node ( 10 ) ; arr [ 2 ] . next . next . next = new Node ( 11 ) ; head = mergeKLists ( arr , k - 1 ) ; printList ( head ) ; } }

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; class GFG { public class Node { public int data ; public Node next ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } static void printList ( Node node ) { while ( node != null ) { Console . Write ( " { 0 } ▁ " , node . data ) ; node = node . next ; } } static Node merge ( Node h1 , Node h2 ) { if ( h1 == null ) return h2 ; if ( h2 == null ) return h1 ; if ( h1 . data < h2 . data ) { h1 . next = merge ( h1 . next , h2 ) ; return h1 ; } else { h2 . next = merge ( h1 , h2 . next ) ; return h2 ; } } public static void Main ( String [ ] args ) { Node head1 = newNode ( 1 ) ; head1 . next = newNode ( 3 ) ; head1 . next . next = newNode ( 5 ) ; Node head2 = newNode ( 0 ) ; head2 . next = newNode ( 2 ) ; head2 . next . next = newNode ( 4 ) ; Node mergedhead = merge ( head1 , head2 ) ; printList ( mergedhead ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GfG { public class Node { public int data ; public Node next ; } static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } static void printList ( Node node ) { while ( node != null ) { Console . Write ( node . data + " ▁ " ) ; node = node . next ; } } static Node mergeUtil ( Node h1 , Node h2 ) { if ( h1 . next == null ) { h1 . next = h2 ; return h1 ; } Node curr1 = h1 , next1 = h1 . next ; Node curr2 = h2 , next2 = h2 . next ; while ( next1 != null && curr2 != null ) { if ( ( curr2 . data ) >= ( curr1 . data ) & & ( curr2 . data ) <= ( next1 . data ) ) { next2 = curr2 . next ; curr1 . next = curr2 ; curr2 . next = next1 ; curr1 = curr2 ; curr2 = next2 ; } else { if ( next1 . next != null ) { next1 = next1 . next ; curr1 = curr1 . next ; } else { next1 . next = curr2 ; return h1 ; } } } return h1 ; } static Node merge ( Node h1 , Node h2 ) { if ( h1 == null ) return h2 ; if ( h2 == null ) return h1 ; if ( h1 . data < h2 . data ) return mergeUtil ( h1 , h2 ) ; else return mergeUtil ( h2 , h1 ) ; } public static void Main ( String [ ] args ) { Node head1 = newNode ( 1 ) ; head1 . next = newNode ( 3 ) ; head1 . next . next = newNode ( 5 ) ; Node head2 = newNode ( 0 ) ; head2 . next = newNode ( 2 ) ; head2 . next . next = newNode ( 4 ) ; Node mergedhead = merge ( head1 , head2 ) ; printList ( mergedhead ) ; } }

Class/struct names: GfG, Node
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class LinkedList { public Node head ; public class Node { public int data ; public Node next ; public Node ( int d ) { data = d ; next = null ; } } void printList ( ) { Node temp = head ; while ( temp != null ) { Console . Write ( temp . data + " ▁ " ) ; temp = temp . next ; } Console . WriteLine ( ) ; } void push ( int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } public void append ( int new_data ) { if ( this . head == null ) { Node n = new Node ( new_data ) ; this . head = n ; return ; } Node n1 = this . head ; Node n2 = new Node ( new_data ) ; while ( n1 . next != null ) { n1 = n1 . next ; } n1 . next = n2 ; n2 . next = null ; } bool isPresent ( Node head , int data ) { Node t = head ; while ( t != null ) { if ( t . data == data ) return true ; t = t . next ; } return false ; } LinkedList getIntersection ( Node head1 , Node head2 ) { HashSet < int > hset = new HashSet < int > ( ) ; Node n1 = head1 ; Node n2 = head2 ; LinkedList result = new LinkedList ( ) ; while ( n1 != null ) { if ( hset . Contains ( n1 . data ) ) { hset . Add ( n1 . data ) ; } else { hset . Add ( n1 . data ) ; } n1 = n1 . next ; } while ( n2 != null ) { if ( hset . Contains ( n2 . data ) ) { result . push ( n2 . data ) ; } n2 = n2 . next ; } return result ; } LinkedList getUnion ( Node head1 , Node head2 ) { SortedDictionary < int , int > hmap = new SortedDictionary < int , int > ( ) ; Node n1 = head1 ; Node n2 = head2 ; LinkedList result = new LinkedList ( ) ; while ( n1 != null ) { if ( hmap . ContainsKey ( n1 . data ) ) { hmap [ n1 . data ] ++ ; } else { hmap [ n1 . data ] = 1 ; } n1 = n1 . next ; } while ( n2 != null ) { if ( hmap . ContainsKey ( n2 . data ) ) { hmap [ n2 . data ] ++ ; } else { hmap [ n2 . data ] = 1 ; } n2 = n2 . next ; } foreach ( int a in hmap . Keys ) { result . append ( a ) ; } return result ; } public static void Main ( string [ ] args ) { LinkedList llist1 = new LinkedList ( ) ; LinkedList llist2 = new LinkedList ( ) ; LinkedList union = new LinkedList ( ) ; LinkedList intersection = new LinkedList ( ) ; llist1 . push ( 20 ) ; llist1 . push ( 4 ) ; llist1 . push ( 15 ) ; llist1 . push ( 10 ) ; llist2 . push ( 10 ) ; llist2 . push ( 2 ) ; llist2 . push ( 4 ) ; llist2 . push ( 8 ) ; intersection = intersection . getIntersection ( llist1 . head , llist2 . head ) ; union = union . getUnion ( llist1 . head , llist2 . head ) ; Console . WriteLine ( " First ▁ List ▁ is " ) ; llist1 . printList ( ) ; Console . WriteLine ( " Second ▁ List ▁ is " ) ; llist2 . printList ( ) ; Console . WriteLine ( " Intersection ▁ List ▁ is " ) ; intersection . printList ( ) ; Console . WriteLine ( " Union ▁ List ▁ is " ) ; union . printList ( ) ; } }

Iterator variables: a
Class/struct names: LinkedList, Node
C# program:
using System ; public class GFG { public class Node { public int data ; public Node next ; } ; static Node swapNodes ( Node head_ref , Node currX , Node currY , Node prevY ) { head_ref = currY ; prevY . next = currX ; Node temp = currY . next ; currY . next = currX . next ; currX . next = temp ; return head_ref ; } static Node recurSelectionSort ( Node head ) { if ( head . next == null ) return head ; Node min = head ; Node beforeMin = null ; Node ptr ; for ( ptr = head ; ptr . next != null ; ptr = ptr . next ) { if ( ptr . next . data < min . data ) { min = ptr . next ; beforeMin = ptr ; } } if ( min != head ) head = swapNodes ( head , head , min , beforeMin ) ; head . next = recurSelectionSort ( head . next ) ; return head ; } static Node sort ( Node head_ref ) { if ( ( head_ref ) == null ) return null ; head_ref = recurSelectionSort ( head_ref ) ; return head_ref ; } static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } static void printList ( Node head ) { while ( head != null ) { Console . Write ( head . data + " ▁ " ) ; head = head . next ; } } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , 6 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 12 ) ; head = push ( head , 10 ) ; Console . WriteLine ( " Linked ▁ list ▁ before ▁ sorting : " ) ; printList ( head ) ; head = sort ( head ) ; Console . Write ( " sorting : " printList ( head ) ; } }

Iterator variables: ptr
Class/struct names: GFG, Node
C# program:
using System ; class GfG { public class Node { public int data ; public Node next ; } static Node getNode ( int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . next = null ; return newNode ; } static void insertAfterNthNode ( Node head , int n , int x ) { if ( head == null ) return ; Node newNode = getNode ( x ) ; Node ptr = head ; int len = 0 , i ; while ( ptr != null ) { len ++ ; ptr = ptr . next ; } ptr = head ; for ( i = 1 ; i <= ( len - n ) ; i ++ ) ptr = ptr . next ; newNode . next = ptr . next ; ptr . next = newNode ; } static void printList ( Node head ) { while ( head != null ) { Console . Write ( head . data + " ▁ " ) ; head = head . next ; } } public static void Main ( String [ ] args ) { Node head = getNode ( 1 ) ; head . next = getNode ( 3 ) ; head . next . next = getNode ( 4 ) ; head . next . next . next = getNode ( 5 ) ; int n = 4 , x = 2 ; Console . Write ( " Original ▁ Linked ▁ List : ▁ " ) ; printList ( head ) ; insertAfterNthNode ( head , n , x ) ; Console . WriteLine ( ) ; Console . Write ( " Linked ▁ List ▁ After ▁ Insertion : ▁ " ) ; printList ( head ) ; } }

Accumulator variables: i, len
Iterator variables: i
Class/struct names: GfG, Node
C# program:
using System ; class GfG { public class Node { public int data ; public Node next ; } static Node getNode ( int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . next = null ; return newNode ; } static void insertAfterNthNode ( Node head , int n , int x ) { if ( head == null ) return ; Node newNode = getNode ( x ) ; Node slow_ptr = head ; Node fast_ptr = head ; for ( int i = 1 ; i <= n - 1 ; i ++ ) fast_ptr = fast_ptr . next ; while ( fast_ptr . next != null ) { slow_ptr = slow_ptr . next ; fast_ptr = fast_ptr . next ; } newNode . next = slow_ptr . next ; slow_ptr . next = newNode ; } static void printList ( Node head ) { while ( head != null ) { Console . Write ( head . data + " ▁ " ) ; head = head . next ; } } public static void Main ( ) { Node head = getNode ( 1 ) ; head . next = getNode ( 3 ) ; head . next . next = getNode ( 4 ) ; head . next . next . next = getNode ( 5 ) ; int n = 4 , x = 2 ; Console . WriteLine ( " Original ▁ Linked ▁ List : ▁ " ) ; printList ( head ) ; insertAfterNthNode ( head , n , x ) ; Console . WriteLine ( ) ; Console . WriteLine ( " Linked ▁ List ▁ After ▁ Insertion : ▁ " ) ; printList ( head ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GfG, Node
C# program:
using System ; public class GFG { class Node { public int data ; public Node next ; public Node ( int data ) { this . data = data ; next = null ; } } static Node head ; static void setMiddleHead ( ) { if ( head == null ) return ; Node one_node = head ; Node two_node = head ; Node prev = null ; while ( two_node != null && two_node . next != null ) { prev = one_node ; two_node = two_node . next . next ; one_node = one_node . next ; } prev . next = prev . next . next ; one_node . next = head ; head = one_node ; } static void push ( int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } static void printList ( Node ptr ) { while ( ptr != null ) { Console . Write ( ptr . data + " ▁ " ) ; ptr = ptr . next ; } Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { head = null ; int i ; for ( i = 5 ; i > 0 ; i -- ) push ( i ) ; Console . Write ( " ▁ list ▁ before : ▁ " ) ; printList ( head ) ; setMiddleHead ( ) ; Console . Write ( " ▁ list ▁ After : ▁ " ) ; printList ( head ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; class GFG { public class Node { public int data ; public Node next , prev ; } ; static Node insert ( Node head_ref , int data ) { Node new_node = new Node ( ) ; new_node . data = data ; if ( head_ref == null ) { new_node . next = new_node ; new_node . prev = new_node ; } else { Node last = ( head_ref ) . prev ; new_node . next = head_ref ; new_node . prev = last ; last . next = ( head_ref ) . prev = new_node ; } head_ref = new_node ; return head_ref ; } static Node merge ( Node first , Node second ) { if ( first == null ) return second ; if ( second == null ) return first ; if ( first . data < second . data ) { first . next = merge ( first . next , second ) ; first . next . prev = first ; first . prev = null ; return first ; } else { second . next = merge ( first , second . next ) ; second . next . prev = second ; second . prev = null ; return second ; } } static Node mergeUtil ( Node head1 , Node head2 ) { if ( head1 == null ) return head2 ; if ( head2 == null ) return head1 ; Node last_node ; if ( head1 . prev . data < head2 . prev . data ) last_node = head2 . prev ; else last_node = head1 . prev ; head1 . prev . next = head2 . prev . next = null ; Node finalHead = merge ( head1 , head2 ) ; finalHead . prev = last_node ; last_node . next = finalHead ; return finalHead ; } static void printList ( Node head ) { Node temp = head ; while ( temp . next != head ) { Console . Write ( temp . data + " ▁ " ) ; temp = temp . next ; } Console . Write ( temp . data + " ▁ " ) ; } public static void Main ( ) { Node head1 = null , head2 = null ; head1 = insert ( head1 , 8 ) ; head1 = insert ( head1 , 5 ) ; head1 = insert ( head1 , 3 ) ; head1 = insert ( head1 , 1 ) ; head2 = insert ( head2 , 11 ) ; head2 = insert ( head2 , 9 ) ; head2 = insert ( head2 , 7 ) ; head2 = insert ( head2 , 2 ) ; Node newHead = mergeUtil ( head1 , head2 ) ; Console . Write ( " Final ▁ Sorted ▁ List : ▁ " ) ; printList ( newHead ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { public class Node { public int data ; public Node prev , next ; } ; static Node newNode ( int val ) { Node temp = new Node ( ) ; temp . data = val ; temp . prev = temp . next = null ; return temp ; } static void printList ( Node head ) { while ( head . next != null ) { Console . Write ( head . data + " ▁ < - > ▁ " ) ; head = head . next ; } Console . WriteLine ( head . data ) ; } static Node insert ( Node head , int val ) { Node temp = newNode ( val ) ; temp . next = head ; ( head ) . prev = temp ; ( head ) = temp ; return head ; } static Node reverseList ( Node head ) { Node left = head , right = head ; while ( right . next != null ) right = right . next ; while ( left != right && left . prev != right ) { int t = left . data ; left . data = right . data ; right . data = t ; left = left . next ; right = right . prev ; } return head ; } public static void Main ( String [ ] args ) { Node head = newNode ( 5 ) ; head = insert ( head , 4 ) ; head = insert ( head , 3 ) ; head = insert ( head , 2 ) ; head = insert ( head , 1 ) ; printList ( head ) ; Console . WriteLine ( " List ▁ After ▁ Reversing " ) ; head = reverseList ( head ) ; printList ( head ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { public class Node { public char data ; public Node next ; public Node prev ; } ; static Node push ( Node head_ref , char new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; new_node . prev = null ; if ( head_ref != null ) head_ref . prev = new_node ; head_ref = new_node ; return head_ref ; } static bool isPalindrome ( Node left ) { if ( left == null ) return true ; Node right = left ; while ( right . next != null ) right = right . next ; while ( left != right ) { if ( left . data != right . data ) return false ; left = left . next ; right = right . prev ; } return true ; } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , ' l ' ) ; head = push ( head , ' e ' ) ; head = push ( head , ' v ' ) ; head = push ( head , ' e ' ) ; head = push ( head , ' l ' ) ; if ( isPalindrome ( head ) ) Console . Write ( " It ▁ is ▁ Palindrome " ) ; else Console . Write ( " Not ▁ Palindrome " ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual void printLevels ( Node node , int low , int high ) { LinkedList < Node > Q = new LinkedList < Node > ( ) ; Node marker = new Node ( 4 ) ; int level = 1 ; Q . AddLast ( node ) ; Q . AddLast ( marker ) ; while ( Q . Count > 0 ) { Node n = Q . First . Value ; Q . RemoveFirst ( ) ; if ( n == marker ) { Console . WriteLine ( " " ) ; level ++ ; if ( Q . Count == 0 level > high ) { break ; } Q . AddLast ( marker ) ; continue ; } if ( level >= low ) { Console . Write ( n . data + " ▁ " ) ; } if ( n . left != null ) { Q . AddLast ( n . left ) ; } if ( n . right != null ) { Q . AddLast ( n . right ) ; } } } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 20 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 22 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 12 ) ; tree . root . left . right . left = new Node ( 10 ) ; tree . root . left . right . right = new Node ( 14 ) ; Console . Write ( " Level ▁ Order ▁ traversal ▁ between ▁ given ▁ two ▁ levels ▁ is ▁ " ) ; tree . printLevels ( tree . root , 2 , 3 ) ; } }

Accumulator variables: level
Class/struct names: BinaryTree, Node
C# program:
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual void printKDistant ( Node node , int k ) { if ( node == null k < 0 ) { return ; } if ( k == 0 ) { Console . Write ( node . data + " ▁ " ) ; return ; } printKDistant ( node . left , k - 1 ) ; printKDistant ( node . right , k - 1 ) ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 8 ) ; tree . printKDistant ( tree . root , 2 ) ; } }

Class/struct names: BinaryTree, Node
C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left , right ; } static Node newNode ( int data ) { Node newnode = new Node ( ) ; newnode . data = data ; newnode . left = newnode . right = null ; return newnode ; } static Boolean printKDistant ( Node root , int klevel ) { Queue < Node > q = new Queue < Node > ( ) ; int level = 1 ; Boolean flag = false ; q . Enqueue ( root ) ; q . Enqueue ( null ) ; while ( q . Count > 0 ) { Node temp = q . Peek ( ) ; if ( level == klevel && temp != null ) { flag = true ; Console . Write ( temp . data + " ▁ " ) ; } q . Dequeue ( ) ; if ( temp == null ) { if ( q . Count > 0 && q . Peek ( ) != null ) q . Enqueue ( null ) ; level += 1 ; if ( level > klevel ) break ; } else { if ( temp . left != null ) q . Enqueue ( temp . left ) ; if ( temp . right != null ) q . Enqueue ( temp . right ) ; } } Console . Write ( " STRNEWLINE " ) ; return flag ; } public static void Main ( String [ ] srga ) { Node root = newNode ( 20 ) ; root . left = newNode ( 10 ) ; root . right = newNode ( 30 ) ; root . left . left = newNode ( 5 ) ; root . left . right = newNode ( 15 ) ; root . left . right . left = newNode ( 12 ) ; root . right . left = newNode ( 25 ) ; root . right . right = newNode ( 40 ) ; Console . Write ( " data ▁ at ▁ level ▁ 1 ▁ : ▁ " ) ; Boolean ret = printKDistant ( root , 1 ) ; if ( ret == false ) Console . Write ( " Number ▁ exceeds ▁ total ▁ " + " number ▁ of ▁ levels STRNEWLINE " ) ; Console . Write ( " data ▁ at ▁ level ▁ 2 ▁ : ▁ " ) ; ret = printKDistant ( root , 2 ) ; if ( ret == false ) Console . Write ( " Number ▁ exceeds ▁ total ▁ " + " number ▁ of ▁ levels STRNEWLINE " ) ; Console . Write ( " data ▁ at ▁ level ▁ 3 ▁ : ▁ " ) ; ret = printKDistant ( root , 3 ) ; if ( ret == false ) Console . Write ( " Number ▁ exceeds ▁ total ▁ " + " number ▁ of ▁ levels STRNEWLINE " ) ; Console . Write ( " data ▁ at ▁ level ▁ 6 ▁ : ▁ " ) ; ret = printKDistant ( root , 6 ) ; if ( ret == false ) Console . Write ( " Number ▁ exceeds ▁ total " + " number ▁ of ▁ levels STRNEWLINE " ) ; } }

Accumulator variables: level
Boolean variables: flag
Class/struct names: GFG, Node
C# program:
using System ; class GFG { class Node { public int data ; public Node left , right ; } ; static void printLeafNodes ( Node root ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { Console . Write ( root . data + " ▁ " ) ; return ; } if ( root . left != null ) printLeafNodes ( root . left ) ; if ( root . right != null ) printLeafNodes ( root . right ) ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } public static void Main ( ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 8 ) ; root . right . left . left = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . left = newNode ( 9 ) ; root . right . right . right = newNode ( 10 ) ; printLeafNodes ( root ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual void printkdistanceNodeDown ( Node node , int k ) { if ( node == null k < 0 ) { return ; } if ( k == 0 ) { Console . Write ( node . data ) ; Console . WriteLine ( " " ) ; return ; } printkdistanceNodeDown ( node . left , k - 1 ) ; printkdistanceNodeDown ( node . right , k - 1 ) ; } public virtual int printkdistanceNode ( Node node , Node target , int k ) { if ( node == null ) { return - 1 ; } if ( node == target ) { printkdistanceNodeDown ( node , k ) ; return 0 ; } int dl = printkdistanceNode ( node . left , target , k ) ; if ( dl != - 1 ) { if ( dl + 1 == k ) { Console . Write ( node . data ) ; Console . WriteLine ( " " ) ; } else { printkdistanceNodeDown ( node . right , k - dl - 2 ) ; } return 1 + dl ; } int dr = printkdistanceNode ( node . right , target , k ) ; if ( dr != - 1 ) { if ( dr + 1 == k ) { Console . Write ( node . data ) ; Console . WriteLine ( " " ) ; } else { printkdistanceNodeDown ( node . left , k - dr - 2 ) ; } return 1 + dr ; } return - 1 ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 20 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 22 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 12 ) ; tree . root . left . right . left = new Node ( 10 ) ; tree . root . left . right . right = new Node ( 14 ) ; Node target = tree . root . left . right ; tree . printkdistanceNode ( tree . root , target , 2 ) ; } }

Class/struct names: BinaryTree, Node