dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class solution { static class Node { int data ; Node left , right ; } ; static Node newNode ( int num ) { Node temp = new Node ( ) ; temp . data = num ; temp . left = temp . right = null ; return temp ; } static Node insert ( Node root , int key ) { if ( root == null ) return newNode ( key ) ; if ( root . data > key ) root . left = insert ( root . left , key ) ; else root . right = insert ( root . right , key ) ; return root ; } static void storeInorder ( Node ptr , Vector < Integer > vect ) { if ( ptr == null ) return ; storeInorder ( ptr . left , vect ) ; vect . add ( ptr . data ) ; storeInorder ( ptr . right , vect ) ; } static void pairSumUtil ( Vector < Integer > vect1 , Vector < Integer > vect2 , int sum ) { int left = 0 ; int right = vect2 . size ( ) - 1 ; while ( left < vect1 . size ( ) && right >= 0 ) { if ( vect1 . get ( left ) + vect2 . get ( right ) == sum ) { System . out . print ( " ( " + vect1 . get ( left ) + " , ▁ " + vect2 . get ( right ) + " ) , ▁ " ) ; left ++ ; right -- ; } else if ( vect1 . get ( left ) + vect2 . get ( right ) < sum ) left ++ ; else right -- ; } } static void pairSum ( Node root1 , Node root2 , int sum ) { Vector < Integer > vect1 = new Vector < Integer > ( ) , vect2 = new Vector < Integer > ( ) ; storeInorder ( root1 , vect1 ) ; storeInorder ( root2 , vect2 ) ; pairSumUtil ( vect1 , vect2 , sum ) ; } public static void main ( String args [ ] ) { Node root1 = null ; root1 = insert ( root1 , 8 ) ; root1 = insert ( root1 , 10 ) ; root1 = insert ( root1 , 3 ) ; root1 = insert ( root1 , 6 ) ; root1 = insert ( root1 , 1 ) ; root1 = insert ( root1 , 5 ) ; root1 = insert ( root1 , 7 ) ; root1 = insert ( root1 , 14 ) ; root1 = insert ( root1 , 13 ) ; Node root2 = null ; root2 = insert ( root2 , 5 ) ; root2 = insert ( root2 , 18 ) ; root2 = insert ( root2 , 2 ) ; root2 = insert ( root2 , 1 ) ; root2 = insert ( root2 , 3 ) ; root2 = insert ( root2 , 4 ) ; int sum = 10 ; pairSum ( root1 , root2 , sum ) ; } }

Accumulator variables: left, right
Class/struct names: Node, solution
Java program:
class solution { static int min_diff , min_diff_key ; static class Node { int key ; Node left , right ; } ; static Node newnode ( int key ) { Node node = new Node ( ) ; node . key = key ; node . left = node . right = null ; return ( node ) ; } static void maxDiffUtil ( Node ptr , int k ) { if ( ptr == null ) return ; if ( ptr . key == k ) { min_diff_key = k ; return ; } if ( min_diff > Math . abs ( ptr . key - k ) ) { min_diff = Math . abs ( ptr . key - k ) ; min_diff_key = ptr . key ; } if ( k < ptr . key ) maxDiffUtil ( ptr . left , k ) ; else maxDiffUtil ( ptr . right , k ) ; } static int maxDiff ( Node root , int k ) { min_diff = 999999999 ; min_diff_key = - 1 ; maxDiffUtil ( root , k ) ; return min_diff_key ; } public static void main ( String args [ ] ) { Node root = newnode ( 9 ) ; root . left = newnode ( 4 ) ; root . right = newnode ( 17 ) ; root . left . left = newnode ( 3 ) ; root . left . right = newnode ( 6 ) ; root . left . right . left = newnode ( 5 ) ; root . left . right . right = newnode ( 7 ) ; root . right . right = newnode ( 22 ) ; root . right . right . left = newnode ( 20 ) ; int k = 18 ; System . out . println ( maxDiff ( root , k ) ) ; } }

Class/struct names: Node, solution
Java program:
public class Tree { Node root ; static class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } public Node insertLevelOrder ( int [ ] arr , Node root , int i ) { if ( i < arr . length ) { Node temp = new Node ( arr [ i ] ) ; root = temp ; root . left = insertLevelOrder ( arr , root . left , 2 * i + 1 ) ; root . right = insertLevelOrder ( arr , root . right , 2 * i + 2 ) ; } return root ; } public void inOrder ( Node root ) { if ( root != null ) { inOrder ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; inOrder ( root . right ) ; } } public static void main ( String args [ ] ) { Tree t2 = new Tree ( ) ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 6 , 6 , 6 } ; t2 . root = t2 . insertLevelOrder ( arr , t2 . root , 0 ) ; t2 . inOrder ( t2 . root ) ; } }

Index/key variables: i
Class/struct names: Node, Tree
Java program:
class node { node left , right ; int data ; boolean color ; node ( int data ) { this . data = data ; left = null ; right = null ; color = true ; } } public class LLRBTREE { private static node root = null ; node rotateLeft ( node myNode ) { System . out . printf ( "left rotation!!NEW_LINE"); node child = myNode . right ; node childLeft = child . left ; child . left = myNode ; myNode . right = childLeft ; return child ; } node rotateRight ( node myNode ) { System . out . printf ( "right rotationNEW_LINE"); node child = myNode . left ; node childRight = child . right ; child . right = myNode ; myNode . left = childRight ; return child ; } boolean isRed ( node myNode ) { if ( myNode == null ) return false ; return ( myNode . color == true ) ; } void swapColors ( node node1 , node node2 ) { boolean temp = node1 . color ; node1 . color = node2 . color ; node2 . color = temp ; } node insert ( node myNode , int data ) { if ( myNode == null ) return new node ( data ) ; if ( data < myNode . data ) myNode . left = insert ( myNode . left , data ) ; else if ( data > myNode . data ) myNode . right = insert ( myNode . right , data ) ; else return myNode ; if ( isRed ( myNode . right ) && ! isRed ( myNode . left ) ) { myNode = rotateLeft ( myNode ) ; swapColors ( myNode , myNode . left ) ; } if ( isRed ( myNode . left ) && isRed ( myNode . left . left ) ) { myNode = rotateRight ( myNode ) ; swapColors ( myNode , myNode . right ) ; } if ( isRed ( myNode . left ) && isRed ( myNode . right ) ) { myNode . color = ! myNode . color ; myNode . left . color = false ; myNode . right . color = false ; } return myNode ; } void inorder ( node node ) { if ( node != null ) { inorder ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; inorder ( node . right ) ; } } public static void main ( String [ ] args ) { LLRBTREE node = new LLRBTREE ( ) ; root = node . insert ( root , 10 ) ; root . color = false ; root = node . insert ( root , 20 ) ; root . color = false ; root = node . insert ( root , 30 ) ; root . color = false ; root = node . insert ( root , 40 ) ; root . color = false ; root = node . insert ( root , 50 ) ; root . color = false ; root = node . insert ( root , 25 ) ; root . color = false ; node . inorder ( root ) ; } }

Boolean variables: color
Class/struct names: LLRBTREE, node
Java program:
static class Node { int data ; Node left , right ; boolean rightThread ; }

Class/struct names: Node
Java program:
public class fullbinarytreepostpre { static int preindex ; static class node { int data ; node left , right ; public node ( int data ) { this . data = data ; } } static node constructTreeUtil ( int pre [ ] , int post [ ] , int l , int h , int size ) { if ( preindex >= size l > h ) return null ; node root = new node ( pre [ preindex ] ) ; preindex ++ ; if ( l == h preindex >= size ) return root ; int i ; for ( i = l ; i <= h ; i ++ ) { if ( post [ i ] == pre [ preindex ] ) break ; } if ( i <= h ) { root . left = constructTreeUtil ( pre , post , l , i , size ) ; root . right = constructTreeUtil ( pre , post , i + 1 , h , size ) ; } return root ; } static node constructTree ( int pre [ ] , int post [ ] , int size ) { preindex = 0 ; return constructTreeUtil ( pre , post , 0 , size - 1 , size ) ; } static void printInorder ( node root ) { if ( root == null ) return ; printInorder ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; printInorder ( root . right ) ; } public static void main ( String [ ] args ) { int pre [ ] = { 1 , 2 , 4 , 8 , 9 , 5 , 3 , 6 , 7 } ; int post [ ] = { 8 , 9 , 4 , 5 , 2 , 6 , 7 , 3 , 1 } ; int size = pre . length ; node root = constructTree ( pre , post , size ) ; System . out . println ( " Inorder ▁ traversal ▁ of ▁ the ▁ constructed ▁ tree : " ) ; printInorder ( root ) ; } }

Index/key variables: i, preindex
Accumulator variables: i, preindex
Iterator variables: i
Class/struct names: fullbinarytreepostpre, node
Java program:
import java . util . * ; class solution { static class Node { int key ; Node left , right ; boolean isThreaded ; } ; static Node createThreaded ( Node root ) { if ( root == null ) return null ; if ( root . left == null && root . right == null ) return root ; if ( root . left != null ) { Node l = createThreaded ( root . left ) ; l . right = root ; l . isThreaded = true ; } if ( root . right == null ) return root ; return createThreaded ( root . right ) ; } static Node leftMost ( Node root ) { while ( root != null && root . left != null ) root = root . left ; return root ; } static void inOrder ( Node root ) { if ( root == null ) return ; Node cur = leftMost ( root ) ; while ( cur != null ) { System . out . print ( cur . key + " ▁ " ) ; if ( cur . isThreaded ) cur = cur . right ; else cur = leftMost ( cur . right ) ; } } static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . left = temp . right = null ; temp . key = key ; return temp ; } public static void main ( String args [ ] ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; createThreaded ( root ) ; System . out . println ( " Inorder ▁ traversal ▁ of ▁ created ▁ " + "threaded tree isNEW_LINE"); inOrder ( root ) ; } }

Boolean variables: isThreaded
Class/struct names: Node, solution
Java program:
class Node { int key ; Node left , right , parent ; public Node ( int key ) { this . key = key ; left = right = parent = null ; } } class BinaryTree { Node root ; Node insert ( Node node , int key ) { if ( node == null ) return new Node ( key ) ; if ( key < node . key ) { node . left = insert ( node . left , key ) ; node . left . parent = node ; } else if ( key > node . key ) { node . right = insert ( node . right , key ) ; node . right . parent = node ; } return node ; } void inorder ( Node root ) { boolean leftdone = false ; while ( root != null ) { if ( ! leftdone ) { while ( root . left != null ) { root = root . left ; } } System . out . print ( root . key + " ▁ " ) ; leftdone = true ; if ( root . right != null ) { leftdone = false ; root = root . right ; } else if ( root . parent != null ) { while ( root . parent != null && root == root . parent . right ) root = root . parent ; if ( root . parent == null ) break ; root = root . parent ; } else break ; } } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = tree . insert ( tree . root , 24 ) ; tree . root = tree . insert ( tree . root , 27 ) ; tree . root = tree . insert ( tree . root , 29 ) ; tree . root = tree . insert ( tree . root , 34 ) ; tree . root = tree . insert ( tree . root , 14 ) ; tree . root = tree . insert ( tree . root , 4 ) ; tree . root = tree . insert ( tree . root , 10 ) ; tree . root = tree . insert ( tree . root , 22 ) ; tree . root = tree . insert ( tree . root , 13 ) ; tree . root = tree . insert ( tree . root , 3 ) ; tree . root = tree . insert ( tree . root , 2 ) ; tree . root = tree . insert ( tree . root , 6 ) ; System . out . println ( " Inorder ▁ traversal ▁ is ▁ " ) ; tree . inorder ( tree . root ) ; } }

Boolean variables: leftdone
Class/struct names: BinaryTree, Node
Java program:
class GFG { private static void printSorted ( int [ ] arr , int start , int end ) { if ( start > end ) return ; printSorted ( arr , start * 2 + 1 , end ) ; System . out . print ( arr [ start ] + " ▁ " ) ; printSorted ( arr , start * 2 + 2 , end ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 5 , 1 , 3 } ; printSorted ( arr , 0 , arr . length - 1 ) ; } }

Index/key variables: start
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; Node ( int d ) { data = d ; left = right = null ; } } class BinaryTree { Node root ; int Ceil ( Node node , int input ) { if ( node == null ) { return - 1 ; } if ( node . data == input ) { return node . data ; } if ( node . data < input ) { return Ceil ( node . right , input ) ; } int ceil = Ceil ( node . left , input ) ; return ( ceil >= input ) ? ceil : node . data ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 8 ) ; tree . root . left = new Node ( 4 ) ; tree . root . right = new Node ( 12 ) ; tree . root . left . left = new Node ( 2 ) ; tree . root . left . right = new Node ( 6 ) ; tree . root . right . left = new Node ( 10 ) ; tree . root . right . right = new Node ( 14 ) ; for ( int i = 0 ; i < 16 ; i ++ ) { System . out . println ( i + " ▁ " + tree . Ceil ( tree . root , i ) ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
class GFG { static class Node { int data ; Node left , right ; } ; static class INT { int a ; INT ( int a ) { this . a = a ; } } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static void printInorder ( Node node ) { if ( node == null ) return ; printInorder ( node . left ) ; System . out . printf ( " % d ▁ " , node . data ) ; printInorder ( node . right ) ; } static Node conBinaryTreeUtil ( int pre [ ] , int preM [ ] , INT preIndex , int l , int h , int size ) { if ( preIndex . a >= size l > h ) return null ; Node root = newNode ( pre [ preIndex . a ] ) ; ++ ( preIndex . a ) ; if ( l == h ) return root ; int i ; for ( i = l ; i <= h ; ++ i ) if ( pre [ preIndex . a ] == preM [ i ] ) break ; if ( i <= h ) { root . left = conBinaryTreeUtil ( pre , preM , preIndex , i , h , size ) ; root . right = conBinaryTreeUtil ( pre , preM , preIndex , l + 1 , i - 1 , size ) ; } return root ; } static void conBinaryTree ( Node root , int pre [ ] , int preMirror [ ] , int size ) { INT preIndex = new INT ( 0 ) ; int preMIndex = 0 ; root = conBinaryTreeUtil ( pre , preMirror , preIndex , 0 , size - 1 , size ) ; printInorder ( root ) ; } public static void main ( String args [ ] ) { int preOrder [ ] = { 1 , 2 , 4 , 5 , 3 , 6 , 7 } ; int preOrderMirror [ ] = { 1 , 3 , 7 , 6 , 2 , 5 , 4 } ; int size = preOrder . length ; Node root = new Node ( ) ; conBinaryTree ( root , preOrder , preOrderMirror , size ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG, INT, Node
Java program:
import java . io . * ; class Node { int data ; Node left , right ; Node ( int d ) { data = d ; left = right = null ; } } class BinaryTree { Node root ; int floor ; int ceil ; public void floorCeilBSTHelper ( Node root , int key ) { while ( root != null ) { if ( root . data == key ) { ceil = root . data ; floor = root . data ; return ; } if ( key > root . data ) { floor = root . data ; root = root . right ; } else { ceil = root . data ; root = root . left ; } } return ; } public void floorCeilBST ( Node root , int key ) { floor = - 1 ; ceil = - 1 ; floorCeilBSTHelper ( root , key ) ; System . out . println ( key + " ▁ " + floor + " ▁ " + ceil ) ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 8 ) ; tree . root . left = new Node ( 4 ) ; tree . root . right = new Node ( 12 ) ; tree . root . left . left = new Node ( 2 ) ; tree . root . left . right = new Node ( 6 ) ; tree . root . right . left = new Node ( 10 ) ; tree . root . right . right = new Node ( 14 ) ; for ( int i = 0 ; i < 16 ; i ++ ) { tree . floorCeilBST ( tree . root , i ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
class GFG { static class node { int key ; int count ; node left , right ; } ; static node newNode ( int item ) { node temp = new node ( ) ; temp . key = item ; temp . left = temp . right = null ; temp . count = 1 ; return temp ; } static void inorder ( node root ) { if ( root != null ) { inorder ( root . left ) ; System . out . print ( root . key + " ( " + root . count + " ) ▁ " ) ; inorder ( root . right ) ; } } static node insert ( node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key == node . key ) { ( node . count ) ++ ; return node ; } if ( key < node . key ) node . left = insert ( node . left , key ) ; else node . right = insert ( node . right , key ) ; return node ; } static node minValueNode ( node node ) { node current = node ; while ( current . left != null ) current = current . left ; return current ; } static node deleteNode ( node root , int key ) { if ( root == null ) return root ; if ( key < root . key ) root . left = deleteNode ( root . left , key ) ; else if ( key > root . key ) root . right = deleteNode ( root . right , key ) ; else { if ( root . count > 1 ) { ( root . count ) -- ; return root ; } if ( root . left == null ) { node temp = root . right ; root = null ; return temp ; } else if ( root . right == null ) { node temp = root . left ; root = null ; return temp ; } node temp = minValueNode ( root . right ) ; root . key = temp . key ; root . right = deleteNode ( root . right , temp . key ) ; } return root ; } public static void main ( String [ ] args ) { node root = null ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 20 ) ; root = insert ( root , 9 ) ; root = insert ( root , 11 ) ; root = insert ( root , 10 ) ; root = insert ( root , 12 ) ; root = insert ( root , 12 ) ; System . out . print ( " Inorder ▁ traversal ▁ of ▁ " + " the ▁ given ▁ tree ▁ " + "NEW_LINE"); inorder ( root ) ; System . out . print ( " Delete 20 "); root = deleteNode ( root , 20 ) ; System . out . print ( " Inorder ▁ traversal ▁ of ▁ " + "the modified tree NEW_LINE"); inorder ( root ) ; System . out . print ( " Delete 12 "); root = deleteNode ( root , 12 ) ; System . out . print ( " Inorder ▁ traversal ▁ of ▁ " + "the modified tree NEW_LINE"); inorder ( root ) ; System . out . print ( " Delete 9 "); root = deleteNode ( root , 9 ) ; System . out . print ( " Inorder ▁ traversal ▁ of ▁ " + "the modified tree NEW_LINE"); inorder ( root ) ; } }

Class/struct names: GFG, node
Java program:
class GfG { static class node { int key ; node left , right ; } static node root = null ; static node newNode ( int item ) { node temp = new node ( ) ; temp . key = item ; temp . left = null ; temp . right = null ; return temp ; } static void inorder ( node root ) { if ( root != null ) { inorder ( root . left ) ; System . out . print ( root . key + " ▁ " ) ; inorder ( root . right ) ; } } static node insert ( node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else node . right = insert ( node . right , key ) ; return node ; } static node minValueNode ( node Node ) { node current = Node ; while ( current . left != null ) current = current . left ; return current ; } static node deleteNode ( node root , int key ) { if ( root == null ) return root ; if ( key < root . key ) root . left = deleteNode ( root . left , key ) ; else if ( key > root . key ) root . right = deleteNode ( root . right , key ) ; else { if ( root . left == null ) { node temp = root . right ; return temp ; } else if ( root . right == null ) { node temp = root . left ; return temp ; } node temp = minValueNode ( root . right ) ; root . key = temp . key ; root . right = deleteNode ( root . right , temp . key ) ; } return root ; } static node changeKey ( node root , int oldVal , int newVal ) { root = deleteNode ( root , oldVal ) ; root = insert ( root , newVal ) ; return root ; } public static void main ( String [ ] args ) { root = insert ( root , 50 ) ; root = insert ( root , 30 ) ; root = insert ( root , 20 ) ; root = insert ( root , 40 ) ; root = insert ( root , 70 ) ; root = insert ( root , 60 ) ; root = insert ( root , 80 ) ; System . out . println ( " Inorder ▁ traversal ▁ of ▁ the ▁ given ▁ tree " ) ; inorder ( root ) ; root = changeKey ( root , 40 , 10 ) ; System . out . println ( " Inorder traversal of the modified tree "); inorder ( root ) ; } }

Class/struct names: GfG, node
Java program:
import java . util . * ; class GfG { static class Node { int key ; Node left , right ; } static Node newNode ( int ele ) { Node temp = new Node ( ) ; temp . key = ele ; temp . left = null ; temp . right = null ; return temp ; } static void printCommon ( Node root1 , Node root2 ) { Stack < Node > s1 = new Stack < Node > ( ) ; Stack < Node > s2 = new Stack < Node > ( ) ; while ( true ) { if ( root1 != null ) { s1 . push ( root1 ) ; root1 = root1 . left ; } else if ( root2 != null ) { s2 . push ( root2 ) ; root2 = root2 . left ; } else if ( ! s1 . isEmpty ( ) && ! s2 . isEmpty ( ) ) { root1 = s1 . peek ( ) ; root2 = s2 . peek ( ) ; if ( root1 . key == root2 . key ) { System . out . print ( root1 . key + " ▁ " ) ; s1 . pop ( ) ; s2 . pop ( ) ; root1 = root1 . right ; root2 = root2 . right ; } else if ( root1 . key < root2 . key ) { s1 . pop ( ) ; root1 = root1 . right ; root2 = null ; } else if ( root1 . key > root2 . key ) { s2 . pop ( ) ; root2 = root2 . right ; root1 = null ; } } else break ; } } static void inorder ( Node root ) { if ( root != null ) { inorder ( root . left ) ; System . out . print ( root . key + " ▁ " ) ; inorder ( root . right ) ; } } static Node insert ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; return node ; } public static void main ( String [ ] args ) { Node root1 = null ; root1 = insert ( root1 , 5 ) ; root1 = insert ( root1 , 1 ) ; root1 = insert ( root1 , 10 ) ; root1 = insert ( root1 , 0 ) ; root1 = insert ( root1 , 4 ) ; root1 = insert ( root1 , 7 ) ; root1 = insert ( root1 , 9 ) ; Node root2 = null ; root2 = insert ( root2 , 10 ) ; root2 = insert ( root2 , 7 ) ; root2 = insert ( root2 , 20 ) ; root2 = insert ( root2 , 4 ) ; root2 = insert ( root2 , 9 ) ; System . out . print ( " Tree ▁ 1 ▁ : ▁ " + "NEW_LINE");  inorder ( root1 ) ; System . out . println ( ) ; System . out . print ( " Tree ▁ 2 ▁ : ▁ " + "NEW_LINE");  inorder ( root2 ) ; System . out . println ( ) ; System . out . println ( " Common ▁ Nodes : ▁ " ) ; printCommon ( root1 , root2 ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . * ; class GFG { static int binarySearch ( int inorder [ ] , int l , int r , int d ) { int mid = ( l + r ) >> 1 ; if ( inorder [ mid ] == d ) return mid ; else if ( inorder [ mid ] > d ) return binarySearch ( inorder , l , mid - 1 , d ) ; else return binarySearch ( inorder , mid + 1 , r , d ) ; } static int ind ; static void leafNodesRec ( int preorder [ ] , int inorder [ ] , int l , int r , int n ) { if ( l == r ) { System . out . printf ( " % d ▁ " , inorder [ l ] ) ; ind = ind + 1 ; return ; } if ( l < 0 l > r r >= n ) return ; int loc = binarySearch ( inorder , l , r , preorder [ ind ] ) ; ind = ind + 1 ; leafNodesRec ( preorder , inorder , l , loc - 1 , n ) ; leafNodesRec ( preorder , inorder , loc + 1 , r , n ) ; } static void leafNodes ( int preorder [ ] , int n ) { int inorder [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) inorder [ i ] = preorder [ i ] ; Arrays . sort ( inorder ) ; leafNodesRec ( preorder , inorder , 0 , n - 1 , n ) ; } public static void main ( String args [ ] ) { int preorder [ ] = { 890 , 325 , 290 , 530 , 965 } ; int n = preorder . length ; leafNodes ( preorder , n ) ; } }

Index/key variables: i, ind, l, mid, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG