dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { public class Node { public char key ; public Node left , right ; } ; static void preorder ( Node root1 , Node root2 , int lvl ) { if ( root1 == null root2 == null ) return ; if ( lvl % 2 == 0 ) { char t = root1 . key ; root1 . key = root2 . key ; root2 . key = t ; } preorder ( root1 . left , root2 . right , lvl + 1 ) ; preorder ( root1 . right , root2 . left , lvl + 1 ) ; } static void reverseAlternate ( Node root ) { preorder ( root . left , root . right , 0 ) ; } static void printInorder ( Node root ) { if ( root == null ) return ; printInorder ( root . left ) ; Console . Write ( root . key + " ▁ " ) ; printInorder ( root . right ) ; } static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . left = temp . right = null ; temp . key = ( char ) key ; return temp ; } public static void Main ( String [ ] args ) { Node root = newNode ( ' a ' ) ; root . left = newNode ( ' b ' ) ; root . right = newNode ( ' c ' ) ; root . left . left = newNode ( ' d ' ) ; root . left . right = newNode ( ' e ' ) ; root . right . left = newNode ( ' f ' ) ; root . right . right = newNode ( ' g ' ) ; root . left . left . left = newNode ( ' h ' ) ; root . left . left . right = newNode ( ' i ' ) ; root . left . right . left = newNode ( ' j ' ) ; root . left . right . right = newNode ( ' k ' ) ; root . right . left . left = newNode ( ' l ' ) ; root . right . left . right = newNode ( ' m ' ) ; root . right . right . left = newNode ( ' n ' ) ; root . right . right . right = newNode ( ' o ' ) ; Console . Write ( " Inorder ▁ Traversal ▁ of ▁ given ▁ tree STRNEWLINE " ) ; printInorder ( root ) ; reverseAlternate ( root ) ; Console . Write ( " STRNEWLINE STRNEWLINE Inorder ▁ Traversal ▁ of ▁ modified ▁ tree STRNEWLINE " ) ; printInorder ( root ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { static int countSink ( int n , int m , int [ ] edgeFrom , int [ ] edgeTo ) { int [ ] mark = new int [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) mark [ edgeFrom [ i ] ] = 1 ; int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( mark [ i ] == 0 ) count ++ ; return count ; } public static void Main ( String [ ] args ) { int n = 4 , m = 2 ; int [ ] edgeFrom = { 2 , 4 } ; int [ ] edgeTo = { 3 , 3 } ; Console . WriteLine ( countSink ( n , m , edgeFrom , edgeTo ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int N = 6 ; static int subsetGraph ( int [ , ] C ) { HashSet < int > vertices = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { vertices . Add ( i ) ; } while ( vertices . Count != 0 ) { if ( vertices . Count == 1 ) { return 1 ; } Boolean someone_removed = false ; foreach ( int x in vertices ) { HashSet < int > values = new HashSet < int > ( ) ; foreach ( int y in vertices ) { if ( y != x ) { values . Add ( C [ x , y ] ) ; } } if ( values . Count == 1 ) { vertices . Remove ( x ) ; someone_removed = true ; break ; } } if ( ! someone_removed ) { break ; } } return ( vertices . Count ) ; } public static void Main ( String [ ] args ) { int [ , ] C = { { 0 , 9 , 2 , 4 , 7 , 8 } , { 9 , 0 , 9 , 9 , 7 , 9 } , { 2 , 9 , 0 , 3 , 7 , 6 } , { 4 , 9 , 3 , 0 , 7 , 1 } , { 7 , 7 , 7 , 7 , 0 , 7 } , { 8 , 9 , 6 , 1 , 7 , 0 } } ; Console . WriteLine ( subsetGraph ( C ) ) ; } }

Iterator variables: i, x, y
Boolean variables: someone_removed
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class Graph { public int V ; public List < int > [ ] adj ; public Graph ( int V ) { this . V = V ; this . adj = new List < int > [ V ] ; for ( int i = 0 ; i < V ; i ++ ) adj [ i ] = new List < int > ( ) ; } public void addEdge ( int u , int v ) { adj [ u ] . Add ( v ) ; adj [ v ] . Add ( u ) ; } public int countEdges ( ) { int sum = 0 ; for ( int i = 0 ; i < V ; i ++ ) sum += adj [ i ] . Count ; return sum / 2 ; } } class GFG { public static void Main ( String [ ] args ) { int V = 9 ; Graph g = new Graph ( V ) ; g . addEdge ( 0 , 1 ) ; g . addEdge ( 0 , 7 ) ; g . addEdge ( 1 , 2 ) ; g . addEdge ( 1 , 7 ) ; g . addEdge ( 2 , 3 ) ; g . addEdge ( 2 , 8 ) ; g . addEdge ( 2 , 5 ) ; g . addEdge ( 3 , 4 ) ; g . addEdge ( 3 , 5 ) ; g . addEdge ( 4 , 5 ) ; g . addEdge ( 5 , 6 ) ; g . addEdge ( 6 , 7 ) ; g . addEdge ( 6 , 8 ) ; g . addEdge ( 7 , 8 ) ; Console . WriteLine ( g . countEdges ( ) ) ; } }

Index/key variables: V, i, u, v
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG, Graph
C# program:
using System ; class GFG { static bool check ( int [ ] degree , int n ) { int deg_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { deg_sum += degree [ i ] ; } return ( 2 * ( n - 1 ) == deg_sum ) ; } public static void Main ( ) { int n = 5 ; int [ ] degree = { 2 , 3 , 1 , 1 , 1 } ; if ( check ( degree , n ) ) { Console . WriteLine ( " Tree " ) ; } else { Console . WriteLine ( " Graph " ) ; } } }

Index/key variables: i
Accumulator variables: deg_sum, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int maxn = 25 ; static bool [ , ] gr = new bool [ maxn , maxn ] ; static bool isCover ( int V , int k , int E ) { int set = ( 1 << k ) - 1 ; int limit = ( 1 << V ) ; bool [ , ] vis = new bool [ maxn , maxn ] ; ; while ( set < limit ) { for ( int i = 0 ; i < maxn ; i ++ ) { for ( int j = 0 ; j < maxn ; j ++ ) { vis [ i , j ] = false ; } } int cnt = 0 ; for ( int j = 1 , v = 1 ; j < limit ; j = j << 1 , v ++ ) { if ( ( set & j ) != 0 ) { for ( int co = 1 ; co <= V ; co ++ ) { if ( gr [ v , co ] && ! vis [ v , co ] ) { vis [ v , co ] = true ; vis [ co , v ] = true ; cnt ++ ; } } } } if ( cnt == E ) return true ; int cO = set & - set ; int rO = set + cO ; set = ( ( ( rO ^ set ) >> 2 ) / cO ) | rO ; } return false ; } static int findMinCover ( int n , int m ) { int left = 1 , right = n ; while ( right > left ) { int mid = ( left + right ) >> 1 ; if ( isCover ( n , mid , m ) == false ) left = mid + 1 ; else right = mid ; } return left ; } static void insertEdge ( int u , int v ) { gr [ u , v ] = true ; gr [ v , u ] = true ; } public static void Main ( String [ ] args ) { int V = 6 , E = 6 ; insertEdge ( 1 , 2 ) ; insertEdge ( 2 , 3 ) ; insertEdge ( 1 , 3 ) ; insertEdge ( 1 , 4 ) ; insertEdge ( 1 , 5 ) ; insertEdge ( 1 , 6 ) ; Console . Write ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " + findMinCover ( V , E ) + " STRNEWLINE " ) ; for ( int i = 0 ; i < maxn ; i ++ ) { for ( int j = 0 ; j < maxn ; j ++ ) { gr [ i , j ] = false ; } } V = 6 ; E = 7 ; insertEdge ( 1 , 2 ) ; insertEdge ( 1 , 3 ) ; insertEdge ( 2 , 3 ) ; insertEdge ( 2 , 4 ) ; insertEdge ( 3 , 5 ) ; insertEdge ( 4 , 5 ) ; insertEdge ( 4 , 6 ) ; Console . Write ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " + findMinCover ( V , E ) + " STRNEWLINE " ) ; } }

Accumulator variables: cnt, co, i, j, v
Iterator variables: co, i, j
Class/struct names: GFG
C# program:
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class GFG { public Node root ; public virtual void morrisTraversalPreorder ( ) { morrisTraversalPreorder ( root ) ; } public virtual void morrisTraversalPreorder ( Node node ) { while ( node != null ) { if ( node . left == null ) { Console . Write ( node . data + " ▁ " ) ; node = node . right ; } else { Node current = node . left ; while ( current . right != null && current . right != node ) { current = current . right ; } if ( current . right == node ) { current . right = null ; node = node . right ; } else { Console . Write ( node . data + " ▁ " ) ; current . right = node ; node = node . left ; } } } } public virtual void preorder ( ) { preorder ( root ) ; } public virtual void preorder ( Node node ) { if ( node != null ) { Console . Write ( node . data + " ▁ " ) ; preorder ( node . left ) ; preorder ( node . right ) ; } } public static void Main ( string [ ] args ) { GFG tree = new GFG ( ) ; 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 ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . left . left . left = new Node ( 8 ) ; tree . root . left . left . right = new Node ( 9 ) ; tree . root . left . right . left = new Node ( 10 ) ; tree . root . left . right . right = new Node ( 11 ) ; tree . morrisTraversalPreorder ( ) ; Console . WriteLine ( " " ) ; tree . preorder ( ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; using System . Collections ; class GFG { static void addEdge ( ArrayList [ ] adj , int u , int v ) { adj [ u ] . Add ( v ) ; } static int findSum ( ArrayList [ ] adj , int V ) { int sum = 0 ; for ( int u = 0 ; u < V ; u ++ ) sum += adj [ u ] . Count ; return sum ; } public static void Main ( string [ ] args ) { int V = 4 ; ArrayList [ ] adj = new ArrayList [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { adj [ i ] = new ArrayList ( ) ; } addEdge ( adj , 0 , 2 ) ; addEdge ( adj , 0 , 3 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 2 , 3 ) ; Console . Write ( " Sum ▁ of ▁ dependencies ▁ is ▁ " + findSum ( adj , V ) ) ; } }

Index/key variables: V, i, u
Accumulator variables: i, sum, u
Iterator variables: i, u
Class/struct names: GFG
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 ; } } class GFG { public Node root ; public virtual void iterativePreorder ( ) { iterativePreorder ( root ) ; } public virtual void iterativePreorder ( Node node ) { if ( node == null ) { return ; } Stack < Node > nodeStack = new Stack < Node > ( ) ; nodeStack . Push ( root ) ; while ( nodeStack . Count > 0 ) { Node mynode = nodeStack . Peek ( ) ; Console . Write ( mynode . data + " ▁ " ) ; nodeStack . Pop ( ) ; if ( mynode . right != null ) { nodeStack . Push ( mynode . right ) ; } if ( mynode . left != null ) { nodeStack . Push ( mynode . left ) ; } } } public static void Main ( string [ ] args ) { GFG tree = new GFG ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 2 ) ; tree . root . left . left = new Node ( 3 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 2 ) ; tree . iterativePreorder ( ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; public class Node { public int data ; public Node next ; public Node ( int d ) { data = d ; next = null ; } } public class LinkedList { Node head ; public void push ( int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } public int getCountRec ( Node node ) { if ( node == null ) return 0 ; return 1 + getCountRec ( node . next ) ; } public int getCount ( ) { return getCountRec ( head ) ; } public static void Main ( String [ ] args ) { LinkedList llist = new LinkedList ( ) ; llist . push ( 1 ) ; llist . push ( 3 ) ; llist . push ( 1 ) ; llist . push ( 2 ) ; llist . push ( 1 ) ; Console . WriteLine ( " Count ▁ of ▁ nodes ▁ is ▁ " + llist . getCount ( ) ) ; } }

Class/struct names: LinkedList, 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 { Node root ; void preorderIterative ( ) { preorderIterative ( root ) ; } void preorderIterative ( Node node ) { if ( node == null ) { return ; } Stack < Node > st = new Stack < Node > ( ) ; Node curr = node ; while ( curr != null st . Count != 0 ) { while ( curr != null ) { Console . Write ( curr . data + " ▁ " ) ; if ( curr . right != null ) st . Push ( curr . right ) ; curr = curr . left ; } if ( st . Count != 0 ) { curr = st . Pop ( ) ; } } } public static void Main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 20 ) ; tree . root . right = new Node ( 30 ) ; tree . root . left . left = new Node ( 40 ) ; tree . root . left . left . left = new Node ( 70 ) ; tree . root . left . right = new Node ( 50 ) ; tree . root . right . left = new Node ( 60 ) ; tree . root . left . left . right = new Node ( 80 ) ; tree . preorderIterative ( ) ; } }

Class/struct names: BinaryTree, Node
C# program:
using System ; public class Node { public int data ; public Node next ; public Node ( int val ) { data = val ; next = null ; } } class GFG { static int frequency = 0 ; static Node push ( Node head , int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; return head ; } static int count ( Node head , int key ) { if ( head == null ) return frequency ; if ( head . data == key ) frequency ++ ; return count ( head . next , key ) ; } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , 1 ) ; head = push ( head , 3 ) ; head = push ( head , 1 ) ; head = push ( head , 2 ) ; head = push ( head , 1 ) ; Console . Write ( " count ▁ of ▁ 1 ▁ is ▁ " + count ( head , 1 ) ) ; } }

Accumulator variables: frequency
Class/struct names: GFG, Node
C# program:
using System ; class GFG { class Node { public int data ; public Node next ; public int flag ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . flag = 0 ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } static bool detectLoop ( Node h ) { while ( h != null ) { if ( h . flag == 1 ) return true ; h . flag = 1 ; h = h . next ; } return false ; } public static void Main ( string [ ] args ) { Node head = null ; head = push ( head , 20 ) ; head = push ( head , 4 ) ; head = push ( head , 15 ) ; head = push ( head , 10 ) ; head . next . next . next . next = head ; if ( detectLoop ( head ) ) Console . Write ( " Loop ▁ found " ) ; else Console . Write ( " No ▁ Loop " ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; public class LinkedList { Node head ; public class Node { public int data ; public Node next ; public Node ( int d ) { data = d ; next = null ; } } public void push ( int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } Boolean detectLoop ( ) { Node slow_p = head , fast_p = head ; while ( slow_p != null && fast_p != null && fast_p . next != null ) { slow_p = slow_p . next ; fast_p = fast_p . next . next ; if ( slow_p == fast_p ) { return true ; } } return false ; } public static void Main ( String [ ] args ) { LinkedList llist = new LinkedList ( ) ; llist . push ( 20 ) ; llist . push ( 4 ) ; llist . push ( 15 ) ; llist . push ( 10 ) ; llist . head . next . next . next . next = llist . head ; Boolean found = llist . detectLoop ( ) ; if ( found ) { Console . WriteLine ( " Loop ▁ Found " ) ; } else { Console . WriteLine ( " No ▁ Loop " ) ; } } }

Class/struct names: LinkedList, Node
C# program:
using System ; public class GFG { public class Node { public int key ; public Node next ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . next = null ; return temp ; } static void printList ( Node head ) { while ( head != null ) { Console . Write ( head . key + " ▁ " ) ; head = head . next ; } Console . WriteLine ( ) ; } static Boolean detectLoop ( Node head ) { Node temp = new Node ( ) ; while ( head != null ) { if ( head . next == null ) { return false ; } if ( head . next == temp ) { return true ; } Node nex = head . next ; head . next = temp ; head = nex ; } return false ; } public static void Main ( String [ ] args ) { Node head = newNode ( 1 ) ; head . next = newNode ( 2 ) ; head . next . next = newNode ( 3 ) ; head . next . next . next = newNode ( 4 ) ; head . next . next . next . next = newNode ( 5 ) ; head . next . next . next . next . next = head . next . next ; Boolean found = detectLoop ( head ) ; if ( found ) { Console . WriteLine ( " Loop ▁ Found " ) ; } else { Console . WriteLine ( " No ▁ Loop " ) ; } } }

Class/struct names: GFG, Node
C# program:
using System ; public class GFG { public class Node { public int key ; public Node next ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . next = null ; return temp ; } static void printList ( Node head ) { while ( head != null ) { Console . Write ( head . key + " ▁ " ) ; head = head . next ; } Console . WriteLine ( ) ; } static int distance ( Node first , Node last ) { int counter = 0 ; Node curr ; curr = first ; while ( curr != last ) { counter += 1 ; curr = curr . next ; } return counter + 1 ; } static bool detectLoop ( Node head ) { Node temp = new Node ( ) ; Node first , last ; first = head ; last = head ; int current_length = 0 ; int prev_length = - 1 ; while ( current_length > prev_length && last != null ) { prev_length = current_length ; current_length = distance ( first , last ) ; last = last . next ; } if ( last == null ) { return false ; } else { return true ; } } public static void Main ( String [ ] args ) { Node head = newNode ( 1 ) ; head . next = newNode ( 2 ) ; head . next . next = newNode ( 3 ) ; head . next . next . next = newNode ( 4 ) ; head . next . next . next . next = newNode ( 5 ) ; head . next . next . next . next . next = head . next . next ; bool found = detectLoop ( head ) ; if ( found ) Console . Write ( " Loop ▁ Found " ) ; else Console . Write ( " No ▁ Loop ▁ Found " ) ; } }

Accumulator variables: counter
Class/struct names: GFG, Node
C# program:
using System ; class LinkedList { public class Node { public char data ; public Node next ; public Node ( char d ) { data = d ; next = null ; } } Node head ; Node slow_ptr , fast_ptr , second_half ; Boolean isPalindrome ( Node head ) { slow_ptr = head ; fast_ptr = head ; Node prev_of_slow_ptr = head ; Node midnode = null ; Boolean res = true ; if ( head != null && head . next != null ) { while ( fast_ptr != null && fast_ptr . next != null ) { fast_ptr = fast_ptr . next . next ; prev_of_slow_ptr = slow_ptr ; slow_ptr = slow_ptr . next ; } if ( fast_ptr != null ) { midnode = slow_ptr ; slow_ptr = slow_ptr . next ; } second_half = slow_ptr ; prev_of_slow_ptr . next = null ; reverse ( ) ; res = compareLists ( head , second_half ) ; reverse ( ) ; if ( midnode != null ) { prev_of_slow_ptr . next = midnode ; midnode . next = second_half ; } else prev_of_slow_ptr . next = second_half ; } return res ; } void reverse ( ) { Node prev = null ; Node current = second_half ; Node next ; while ( current != null ) { next = current . next ; current . next = prev ; prev = current ; current = next ; } second_half = prev ; } Boolean compareLists ( Node head1 , Node head2 ) { Node temp1 = head1 ; Node temp2 = head2 ; while ( temp1 != null && temp2 != null ) { if ( temp1 . data == temp2 . data ) { temp1 = temp1 . next ; temp2 = temp2 . next ; } else return false ; } if ( temp1 == null && temp2 == null ) return true ; return false ; } public void push ( char new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; } void printList ( Node ptr ) { while ( ptr != null ) { Console . Write ( ptr . data + " - > " ) ; ptr = ptr . next ; } Console . WriteLine ( " NULL " ) ; } public static void Main ( String [ ] args ) { LinkedList llist = new LinkedList ( ) ; char [ ] str = { ' a ' , ' b ' , ' a ' , ' c ' , ' a ' , ' b ' , ' a ' } ; for ( int i = 0 ; i < 7 ; i ++ ) { llist . push ( str [ i ] ) ; llist . printList ( llist . head ) ; if ( llist . isPalindrome ( llist . head ) != false ) { Console . WriteLine ( " Is ▁ Palindrome " ) ; Console . WriteLine ( " " ) ; } else { Console . WriteLine ( " Not ▁ Palindrome " ) ; Console . WriteLine ( " " ) ; } } } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: res
Class/struct names: LinkedList, Node
C# program:
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node next ; public Node ( ) { data = 0 ; next = null ; } } public class GFG { 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 node ) { while ( node != null ) { Console . Write ( node . data + " ▁ " ) ; node = node . next ; } } static void removeDuplicates ( Node head ) { Dictionary < int , bool > track = new Dictionary < int , bool > ( ) ; Node temp = head ; while ( temp != null ) { if ( ! track . ContainsKey ( temp . data ) ) { Console . Write ( temp . data + " ▁ " ) ; track . Add ( temp . data , true ) ; } temp = temp . next ; } } static public void Main ( ) { Node head = null ; head = push ( head , 20 ) ; head = push ( head , 13 ) ; head = push ( head , 13 ) ; head = push ( head , 11 ) ; head = push ( head , 11 ) ; head = push ( head , 11 ) ; Console . Write ( " Linked ▁ list ▁ before ▁ duplicate ▁ removal ▁ " ) ; printList ( head ) ; Console . Write ( " STRNEWLINE Linked ▁ list ▁ after ▁ duplicate ▁ removal ▁ " ) ; removeDuplicates ( head ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class Node { public int data ; public Node next ; public Node ( int d ) { data = d ; next = null ; } } public class LinkedList { Node head ; public void swapNodes ( int x , int y ) { if ( x == y ) return ; Node prevX = null , currX = head ; while ( currX != null && currX . data != x ) { prevX = currX ; currX = currX . next ; } Node prevY = null , currY = head ; while ( currY != null && currY . data != y ) { prevY = currY ; currY = currY . next ; } if ( currX == null currY == null ) return ; if ( prevX != null ) prevX . next = currY ; else head = currY ; if ( prevY != null ) prevY . next = currX ; else head = currX ; Node temp = currX . next ; currX . next = currY . next ; currY . next = temp ; } public void push ( int new_data ) { Node new_Node = new Node ( new_data ) ; new_Node . next = head ; head = new_Node ; } public void printList ( ) { Node tNode = head ; while ( tNode != null ) { Console . Write ( tNode . data + " ▁ " ) ; tNode = tNode . next ; } } public static void Main ( String [ ] args ) { LinkedList llist = new LinkedList ( ) ; llist . push ( 7 ) ; llist . push ( 6 ) ; llist . push ( 5 ) ; llist . push ( 4 ) ; llist . push ( 3 ) ; llist . push ( 2 ) ; llist . push ( 1 ) ; Console . Write ( " swapNodes ( ) " llist . printList ( ) ; llist . swapNodes ( 4 , 3 ) ; Console . Write ( " swapNodes ( ) " llist . printList ( ) ; } }

Class/struct names: LinkedList, Node
C# program:
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node left , right ; public Node ( int data ) { this . data = data ; this . left = this . right = null ; } } ; class GFG { Node root ; void postorder ( Node head ) { Node temp = root ; HashSet < Node > visited = new HashSet < Node > ( ) ; while ( ( temp != null && ! visited . Contains ( temp ) ) ) { if ( temp . left != null && ! visited . Contains ( temp . left ) ) temp = temp . left ; else if ( temp . right != null && ! visited . Contains ( temp . right ) ) temp = temp . right ; else { Console . Write ( temp . data + " ▁ " ) ; visited . Add ( temp ) ; temp = head ; } } } public static void Main ( String [ ] args ) { GFG gfg = new GFG ( ) ; gfg . root = new Node ( 8 ) ; gfg . root . left = new Node ( 3 ) ; gfg . root . right = new Node ( 10 ) ; gfg . root . left . left = new Node ( 1 ) ; gfg . root . left . right = new Node ( 6 ) ; gfg . root . left . right . left = new Node ( 4 ) ; gfg . root . left . right . right = new Node ( 7 ) ; gfg . root . right . right = new Node ( 14 ) ; gfg . root . right . right . left = new Node ( 13 ) ; gfg . postorder ( gfg . root ) ; } }

Class/struct names: GFG, Node