dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class Graph { int V ; Vector < Integer > [ ] adj ; Graph ( int V ) { this . V = V ; this . adj = new Vector [ V ] ; for ( int i = 0 ; i < V ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; } void addEdge ( int u , int v ) { adj [ u ] . add ( v ) ; adj [ v ] . add ( u ) ; } int countEdges ( ) { int sum = 0 ; for ( int i = 0 ; i < V ; i ++ ) sum += adj [ i ] . size ( ) ; return sum / 2 ; } } class GFG { public static void main ( String [ ] args ) throws IOException { 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 ) ; System . out . println ( g . countEdges ( ) ) ; } }

Index/key variables: V, i, u, v
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG, Graph
Java program:
import java . util . ArrayDeque ; import java . util . Deque ; class GFG { static int V = 5 ; static boolean isBipartiteUtil ( int G [ ] [ ] , int src , int colorArr [ ] ) { colorArr [ src ] = 1 ; Deque < Integer > q = new ArrayDeque < > ( ) ; q . push ( src ) ; while ( ! q . isEmpty ( ) ) { int u = q . peek ( ) ; q . pop ( ) ; for ( int v = 0 ; v < V ; ++ v ) { if ( G [ u ] [ v ] == - 1 && colorArr [ v ] == - 1 ) { colorArr [ v ] = 1 - colorArr [ u ] ; q . push ( v ) ; } else if ( G [ u ] [ v ] == colorArr [ u ] && colorArr [ v ] == colorArr [ u ] ) return false ; } } return true ; } static boolean isBipartite ( int G [ ] [ ] ) { int colorArr [ ] = new int [ V ] ; for ( int i = 0 ; i < V ; ++ i ) colorArr [ i ] = - 1 ; for ( int i = 0 ; i < V ; i ++ ) if ( colorArr [ i ] == - 1 ) if ( isBipartiteUtil ( G , i , colorArr ) == false ) return false ; return true ; } static boolean canBeDividedinTwoCliques ( int G [ ] [ ] ) { int GC [ ] [ ] = new int [ V ] [ V ] ; for ( int i = 0 ; i < V ; i ++ ) for ( int j = 0 ; j < V ; j ++ ) GC [ i ] [ j ] = ( i != j ) ? - GC [ i ] [ j ] : 0 ; return isBipartite ( GC ) ; } public static void main ( String [ ] args ) { int G [ ] [ ] = { { 0 , 1 , 1 , 1 , 0 } , { 1 , 0 , 1 , 0 , 0 } , { 1 , 1 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 , 1 } , { 0 , 0 , 0 , 1 , 0 } } ; if ( canBeDividedinTwoCliques ( G ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: V, i, j, src, u, v
Accumulator variables: i, j
Iterator variables: i, j, v
Class/struct names: GFG
Java program:
class GFG { static boolean 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 ( String [ ] args ) { int n = 5 ; int degree [ ] = { 2 , 3 , 1 , 1 , 1 } ; if ( check ( degree , n ) ) { System . out . println ( " Tree " ) ; } else { System . out . println ( " Graph " ) ; } } }

Index/key variables: i
Accumulator variables: deg_sum, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static final int maxn = 25 ; static boolean [ ] [ ] gr = new boolean [ maxn ] [ maxn ] ; static boolean isCover ( int V , int k , int E ) { int set = ( 1 << k ) - 1 ; int limit = ( 1 << V ) ; boolean [ ] [ ] vis = new boolean [ 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 ) ; System . out . print ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " + findMinCover ( V , E ) + "NEW_LINE"); 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 ) ; System . out . print ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " + findMinCover ( V , E ) + "NEW_LINE"); } }

Index/key variables: co, i, j, maxn, u, v
Accumulator variables: cnt, co, i, j, v
Iterator variables: co, i, j
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void morrisTraversalPreorder ( ) { morrisTraversalPreorder ( root ) ; } void morrisTraversalPreorder ( Node node ) { while ( node != null ) { if ( node . left == null ) { System . out . print ( 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 { System . out . print ( node . data + " ▁ " ) ; current . right = node ; node = node . left ; } } } } void preorder ( ) { preorder ( root ) ; } void preorder ( Node node ) { if ( node != null ) { System . out . print ( node . data + " ▁ " ) ; preorder ( node . left ) ; preorder ( node . right ) ; } } 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 ( 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 ( ) ; System . out . println ( " " ) ; tree . preorder ( ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . Vector ; class Test { static void addEdge ( Vector < Integer > adj [ ] , int u , int v ) { adj [ u ] . addElement ( ( v ) ) ; } static int findSum ( Vector < Integer > adj [ ] , int V ) { int sum = 0 ; for ( int u = 0 ; u < V ; u ++ ) sum += adj [ u ] . size ( ) ; return sum ; } public static void main ( String [ ] args ) { int V = 4 ; @ SuppressWarnings ( " unchecked " ) Vector < Integer > adj [ ] = new Vector [ V ] ; for ( int i = 0 ; i < adj . length ; i ++ ) { adj [ i ] = new Vector < > ( ) ; } addEdge ( adj , 0 , 2 ) ; addEdge ( adj , 0 , 3 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 2 , 3 ) ; System . out . println ( " 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: Test
Java program:
import java . util . Stack ; class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void iterativePreorder ( ) { iterativePreorder ( root ) ; } void iterativePreorder ( Node node ) { if ( node == null ) { return ; } Stack < Node > nodeStack = new Stack < Node > ( ) ; nodeStack . push ( root ) ; while ( nodeStack . empty ( ) == false ) { Node mynode = nodeStack . peek ( ) ; System . out . print ( 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 [ ] ) { BinaryTree tree = new BinaryTree ( ) ; 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: BinaryTree, Node
Java program:
class Node { int data ; Node next ; Node ( int d ) { data = d ; next = null ; } } 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 ) ; System . out . println ( " Count ▁ of ▁ nodes ▁ is ▁ " + llist . getCount ( ) ) ; } }

Class/struct names: LinkedList, Node
Java program:
import java . util . Stack ; class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } 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 . isEmpty ( ) ) { while ( curr != null ) { System . out . print ( curr . data + " ▁ " ) ; if ( curr . right != null ) st . push ( curr . right ) ; curr = curr . left ; } if ( ! st . isEmpty ( ) ) { 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
Java program:
import java . io . * ; import java . util . * ; class Node { int data ; Node next ; 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 ) ; System . out . print ( " count ▁ of ▁ 1 ▁ is ▁ " + count ( head , 1 ) ) ; } }

Accumulator variables: frequency
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node next ; 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 boolean 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 ) ) System . out . print ( " Loop ▁ found " ) ; else System . out . print ( " No ▁ Loop " ) ; } }

Class/struct names: GFG, Node
Java program:
class LinkedList { Node head ; class Node { int data ; Node next ; 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 ; } void detectLoop ( ) { Node slow_p = head , fast_p = head ; int flag = 0 ; 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 ) { flag = 1 ; break ; } } if ( flag == 1 ) System . out . println ( " Loop ▁ found " ) ; else System . out . println ( " Loop ▁ not ▁ found " ) ; } 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 ; llist . detectLoop ( ) ; } }

Class/struct names: LinkedList, Node
Java program:
class GFG { static class Node { int key ; 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 ) { System . out . print ( head . key + " ▁ " ) ; head = head . next ; } System . out . println ( ) ; } 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 ) System . out . println ( " Loop ▁ Found " ) ; else System . out . println ( " No ▁ Loop " ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int key ; 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 ) { System . out . print ( head . key + " ▁ " ) ; head = head . next ; } System . out . println ( ) ; } 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 boolean 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 ; boolean found = detectLoop ( head ) ; if ( found ) System . out . print ( " Loop ▁ Found " ) ; else System . out . print ( " No ▁ Loop ▁ Found " ) ; } }

Accumulator variables: counter
Class/struct names: GFG, Node
Java program:
class LinkedList { class Node { char data ; Node next ; 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 ) { System . out . print ( ptr . data + " - > " ) ; ptr = ptr . next ; } System . out . println ( " NULL " ) ; } public static void main ( String [ ] args ) { LinkedList llist = new LinkedList ( ) ; char str [ ] = { ' a ' , ' b ' , ' a ' , ' c ' , ' a ' , ' b ' , ' a ' } ; String string = new String ( str ) ; for ( int i = 0 ; i < 7 ; i ++ ) { llist . push ( str [ i ] ) ; llist . printList ( llist . head ) ; if ( llist . isPalindrome ( llist . head ) != false ) { System . out . println ( " Is ▁ Palindrome " ) ; System . out . println ( " " ) ; } else { System . out . println ( " Not ▁ Palindrome " ) ; System . out . println ( " " ) ; } } } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: res
Class/struct names: LinkedList, Node
Java program:
import java . io . * ; import java . util . * ; class Node { int data ; Node next ; Node ( ) { data = 0 ; next = null ; } } 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 ) { System . out . print ( node . data + " ▁ " ) ; node = node . next ; } } static void removeDuplicates ( Node head ) { HashMap < Integer , Boolean > track = new HashMap < > ( ) ; Node temp = head ; while ( temp != null ) { if ( ! track . containsKey ( temp . data ) ) { System . out . print ( temp . data + " ▁ " ) ; } track . put ( temp . data , true ) ; temp = temp . next ; } } public static void main ( String [ ] args ) { 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 ) ; System . out . print ( " Linked ▁ list ▁ before ▁ duplicate ▁ removal ▁ " ) ; printList ( head ) ; System . out . print ( " Linked list after duplicate removal "); removeDuplicates ( head ) ; } }

Class/struct names: GFG, Node
Java program:
class Node { int data ; Node next ; Node ( int d ) { data = d ; next = null ; } } 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 ) { System . out . print ( 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 ) ; System . out . print ( " Linked list before calling swapNodes ( ) "); llist . printList ( ) ; llist . swapNodes ( 4 , 3 ) ; System . out . print ( " Linked list after calling swapNodes ( ) "); llist . printList ( ) ; } }

Class/struct names: LinkedList, Node
Java program:
import java . util . * ; class Node { int data ; Node left , right ; 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 < > ( ) ; 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 { System . out . printf ( " % d ▁ " , 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
Java program:
import java . util . * ; class Node { int data ; Node next ; Node ( int d ) { data = d ; next = null ; } } class LinkedListIntersect { public static void main ( String [ ] args ) { Node n1 = new Node ( 1 ) ; n1 . next = new Node ( 2 ) ; n1 . next . next = new Node ( 3 ) ; n1 . next . next . next = new Node ( 4 ) ; n1 . next . next . next . next = new Node ( 5 ) ; n1 . next . next . next . next . next = new Node ( 6 ) ; n1 . next . next . next . next . next . next = new Node ( 7 ) ; Node n2 = new Node ( 10 ) ; n2 . next = new Node ( 9 ) ; n2 . next . next = new Node ( 8 ) ; n2 . next . next . next = n1 . next . next . next ; Print ( n1 ) ; Print ( n2 ) ; System . out . println ( MegeNode ( n1 , n2 ) . data ) ; } public static void Print ( Node n ) { Node cur = n ; while ( cur != null ) { System . out . print ( cur . data + " ▁ " ) ; cur = cur . next ; } System . out . println ( ) ; } public static Node MegeNode ( Node n1 , Node n2 ) { HashSet < Node > hs = new HashSet < Node > ( ) ; while ( n1 != null ) { hs . add ( n1 ) ; n1 = n1 . next ; } while ( n2 != null ) { if ( hs . contains ( n2 ) ) { return n2 ; } n2 = n2 . next ; } return null ; } }

Class/struct names: LinkedListIntersect, Node
Java program:
class GFG { static class Node { int data ; Node left , right ; boolean visited ; } static void postorder ( Node head ) { Node temp = head ; while ( temp != null && temp . visited == false ) { if ( temp . left != null && temp . left . visited == false ) temp = temp . left ; else if ( temp . right != null && temp . right . visited == false ) temp = temp . right ; else { System . out . printf ( " % d ▁ " , temp . data ) ; temp . visited = true ; temp = head ; } } } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; node . visited = false ; return ( node ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 8 ) ; root . left = newNode ( 3 ) ; root . right = newNode ( 10 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 6 ) ; root . left . right . left = newNode ( 4 ) ; root . left . right . right = newNode ( 7 ) ; root . right . right = newNode ( 14 ) ; root . right . right . left = newNode ( 13 ) ; postorder ( root ) ; } }

Boolean variables: visited
Class/struct names: GFG, Node