codeparrot/xlcost-text-to-code huggingface dataset:
Maximize sum of Bitwise AND of same | C ++ program for the above approach ; Function to calculate sum of Bitwise AND of same indexed elements of the arrays p [ ] and arr [ ] ; Stores the resultant sum ; Traverse the array ; Update sum of Bitwise AND ; Return the value obtained ; Function to generate all permutations and calculate the maximum sum of Bitwise AND of same indexed elements present in any permutation and an array arr [ ] ; If the size of the array is N ; Calculate cost of permutation ; Generate all permutations ; Update chosen [ i ] ; Update the permutation p [ ] ; Generate remaining permutations ; Return the resultant sum ; Function to find the maximum sum of Bitwise AND of same indexed elements in a permutation of first N natural numbers and arr [ ] ; Stores the resultant maximum sum ; Stores the generated permutation P ; Function call to store result ; Print the result ; Driven Program ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calcScore ( vector < int > p , int arr [ ] , int N ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += ( p [ i ] & arr [ i ] ) ; } return ans ; } int getMaxUtil ( vector < int > p , int arr [ ] , int ans , bool chosen [ ] , int N ) { if ( p . size ( ) == N ) { ans = max ( ans , calcScore ( p , arr , N ) ) ; return ans ; } for ( int i = 0 ; i < N ; i ++ ) { if ( chosen [ i ] ) { continue ; } chosen [ i ] = true ; p . push_back ( i ) ; ans = getMaxUtil ( p , arr , ans , chosen , N ) ; chosen [ i ] = false ; p . pop_back ( ) ; } return ans ; } void getMax ( int arr [ ] , int N ) { int ans = 0 ; bool chosen [ N ] ; for ( int i = 0 ; i < N ; i ++ ) chosen [ i ] = false ; vector < int > p ; int res = getMaxUtil ( p , arr , ans , chosen , N ) ; cout << res ; } int main ( ) { int arr [ ] = { 4 , 2 , 3 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getMax ( arr , N ) ; return 0 ; }
Sum of array elements whose count of set bits are unique | C ++ program for the approach ; Function to count the number of set bits in an integer N ; Stores the count of set bits ; Iterate until N is non - zero ; Stores the resultant count ; Function to calculate sum of all array elements whose count of set bits are unique ; Stores frequency of all possible count of set bits ; Stores the sum of array elements ; Traverse the array ; Count the number of set bits ; Traverse the array And Update the value of ans ; If frequency is 1 ; Driver Code
#include <iostream> NEW_LINE #include <bits/stdc++.h> NEW_LINE using namespace std ; int setBitCount ( int n ) { int ans = 0 ; while ( n ) { ans += n & 1 ; n >>= 1 ; } return ans ; } int getSum ( int * arr , int n ) { map < int , int > mp ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int key = setBitCount ( arr [ i ] ) ; mp [ key ] += 1 ; } for ( int i = 0 ; i < n ; i ++ ) { int key = setBitCount ( arr [ i ] ) ; if ( mp [ key ] == 1 ) ans += arr [ i ] ; } cout << ans ; } int main ( ) { int arr [ 5 ] = { 8 , 3 , 7 , 5 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getSum ( arr , n ) ; return 0 ; }
Print indices of pair of array elements required to be removed to split array into 3 equal sum subarrays | C ++ program for the above approach ; Function to check if array can be split into three equal sum subarrays by removing a pair ; Stores prefix sum array ; Copy array elements ; Traverse the array ; Stores sums of all three subarrays ; Sum of left subarray ; Sum of middle subarray ; Sum of right subarray ; Check if sum of subarrays are equal ; Print the possible pair ; If no such pair exists , print - 1 ; Driver Code ; Given array ; Size of the array
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findSplit ( int arr [ ] , int N ) { vector < int > sum ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { sum [ i ] = arr [ i ] ; } for ( int i = 1 ; i < N ; i ++ ) { sum [ i ] += sum [ i - 1 ] ; } for ( int l = 1 ; l <= N - 4 ; l ++ ) { for ( int r = l + 2 ; r <= N - 2 ; r ++ ) { int lsum = 0 , rsum = 0 , msum = 0 ; lsum = sum [ l - 1 ] ; msum = sum [ r - 1 ] - sum [ l ] ; rsum = sum [ N - 1 ] - sum [ r ] ; if ( lsum == rsum && rsum == msum ) { cout << l << " ▁ " << r << endl ; return ; } } } cout << -1 << endl ; } int main ( ) { int arr [ ] = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findSplit ( arr , N ) ; return 0 ; }
Print indices of pair of array elements required to be removed to split array into 3 equal sum subarrays | C ++ program for the above approach ; Function to check if array can be split into three equal sum subarrays by removing a pair ; Two pointers l and r ; Stores prefix sum array ; Traverse the array ; Two pointer approach ; Sum of left subarray ; Sum of middle subarray ; Sum of right subarray ; Print split indices if sum is equal ; Move left pointer if lsum < rsum ; Move right pointer if rsum > lsum ; Move both pointers if lsum = rsum but they are not equal to msum ; If no possible pair exists , print - 1 ; Driver Code ; Given array ; Size of the array
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findSplit ( int arr [ ] , int N ) { int l = 1 , r = N - 2 ; int lsum , msum , rsum ; vector < int > sum ( N ) ; sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { sum [ i ] = sum [ i - 1 ] + arr [ i ] ; } while ( l < r ) { lsum = sum [ l - 1 ] ; msum = sum [ r - 1 ] - sum [ l ] ; rsum = sum [ N - 1 ] - sum [ r ] ; if ( lsum == msum and msum == rsum ) { cout << l << " ▁ " << r << endl ; return ; } if ( lsum < rsum ) l ++ ; else if ( lsum > rsum ) r -- ; else { l ++ ; r -- ; } } cout << -1 << endl ; } int main ( ) { int arr [ ] = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findSplit ( arr , N ) ; return 0 ; }
Number of subtrees having odd count of even numbers | C implementation to find number of subtrees having odd count of even numbers ; A binary tree Node ; Helper function that allocates a new Node with the given data and NULL left and right pointers . ; Returns count of subtrees having odd count of even numbers ; base condition ; count even nodes in left subtree ; Add even nodes in right subtree ; Check if root data is an even number ; if total count of even numbers for the subtree is odd ; Total count of even nodes of the subtree ; A wrapper over countRec ( ) ; Driver program to test above ; binary tree formation ; 2 ; / \ ; 1 3 ; / \ / \ ; 4 10 8 5 ; / ; 6
#include <bits/stdc++.h> NEW_LINE struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int countRec ( struct Node * root , int * pcount ) { if ( root == NULL ) return 0 ; int c = countRec ( root -> left , pcount ) ; c += countRec ( root -> right , pcount ) ; if ( root -> data % 2 == 0 ) c += 1 ; if ( c % 2 != 0 ) ( * pcount ) ++ ; return c ; } int countSubtrees ( Node * root ) { int count = 0 ; int * pcount = & count ; countRec ( root , pcount ) ; return count ; } int main ( ) { struct Node * root = newNode ( 2 ) ; root -> left = newNode ( 1 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 10 ) ; root -> right -> left = newNode ( 8 ) ; root -> right -> right = newNode ( 5 ) ; root -> left -> right -> left = newNode ( 6 ) ; printf ( " Count ▁ = ▁ % d " , countSubtrees ( root ) ) ; return 0 ; }
Inorder Successor of a node in Binary Tree | CPP program to find inorder successor of a node ; A Binary Tree Node ; Temporary node for case 2 ; Utility function to create a new tree node ; function to find left most node in a tree ; function to find right most node in a tree ; recursive function to find the Inorder Scuccessor when the right child of node x is NULL ; function to find inorder successor of a node ; Case1 : If right child is not NULL ; Case2 : If right child is NULL ; case3 : If x is the right most node ; Driver program to test above functions ; Case 1 ; case 2 ; case 3
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * temp = new Node ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } Node * leftMostNode ( Node * node ) { while ( node != NULL && node -> left != NULL ) node = node -> left ; return node ; } Node * rightMostNode ( Node * node ) { while ( node != NULL && node -> right != NULL ) node = node -> right ; return node ; } Node * findInorderRecursive ( Node * root , Node * x ) { if ( ! root ) return NULL ; if ( root == x || ( temp = findInorderRecursive ( root -> left , x ) ) || ( temp = findInorderRecursive ( root -> right , x ) ) ) { if ( temp ) { if ( root -> left == temp ) { cout << " Inorder ▁ Successor ▁ of ▁ " << x -> data ; cout << " ▁ is ▁ " << root -> data << " STRNEWLINE " ; return NULL ; } } return root ; } return NULL ; } void inorderSuccesor ( Node * root , Node * x ) { if ( x -> right != NULL ) { Node * inorderSucc = leftMostNode ( x -> right ) ; cout << " Inorder ▁ Successor ▁ of ▁ " << x -> data << " ▁ is ▁ " ; cout << inorderSucc -> data << " STRNEWLINE " ; } if ( x -> right == NULL ) { int f = 0 ; Node * rightMost = rightMostNode ( root ) ; if ( rightMost == x ) cout << " No ▁ inorder ▁ successor ! ▁ Right ▁ most ▁ node . STRNEWLINE " ; else findInorderRecursive ( root , x ) ; } } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; inorderSuccesor ( root , root -> right ) ; inorderSuccesor ( root , root -> left -> left ) ; inorderSuccesor ( root , root -> right -> right ) ; return 0 ; }
Binary Tree | Set 1 ( Introduction ) |  ; struct containing left and right child of current node and key value ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; Node ( int val ) { data = val ; left = NULL ; right = NULL ; } } ; int main ( ) { struct Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; return 0 ; }
Find distance from root to given node in a binary tree | C ++ program to find distance of a given node from root . ; A Binary Tree Node ; A utility function to create a new Binary Tree Node ; Returns - 1 if x doesn 't exist in tree. Else returns distance of x from root ; Base case ; Initialize distance ; Check if x is present at root or in left subtree or right subtree . ; Driver Program to test above functions
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> data = item ; temp -> left = temp -> right = NULL ; return temp ; } int findDistance ( Node * root , int x ) { if ( root == NULL ) return -1 ; int dist = -1 ; if ( ( root -> data == x ) || ( dist = findDistance ( root -> left , x ) ) >= 0 || ( dist = findDistance ( root -> right , x ) ) >= 0 ) return dist + 1 ; return dist ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 10 ) ; root -> right = newNode ( 15 ) ; root -> left -> left = newNode ( 20 ) ; root -> left -> right = newNode ( 25 ) ; root -> left -> right -> right = newNode ( 45 ) ; root -> right -> left = newNode ( 30 ) ; root -> right -> right = newNode ( 35 ) ; cout << findDistance ( root , 45 ) ; return 0 ; }
Find right sibling of a binary tree with parent pointers | C program to print right sibling of a node ; A Binary Tree Node ; A utility function to create a new Binary Tree Node ; Method to find right sibling ; GET Parent pointer whose right child is not a parent or itself of this node . There might be case when parent has no right child , but , current node is left child of the parent ( second condition is for that ) . ; Move to the required child , where right sibling can be present ; find right sibling in the given subtree ( from current node ) , when level will be 0 ; Iterate through subtree ; if no child are there , we cannot have right sibling in this path ; This is the case when we reach 9 node in the tree , where we need to again recursively find the right sibling ; Driver Program to test above functions ; passing 10
#include <bits/stdc++.h> NEW_LINE struct Node { int data ; Node * left , * right , * parent ; } ; Node * newNode ( int item , Node * parent ) { Node * temp = new Node ; temp -> data = item ; temp -> left = temp -> right = NULL ; temp -> parent = parent ; return temp ; } Node * findRightSibling ( Node * node , int level ) { if ( node == NULL node -> parent == NULL ) return NULL ; while ( node -> parent -> right == node || ( node -> parent -> right == NULL && node -> parent -> left == node ) ) { if ( node -> parent == NULL node -> parent -> parent == NULL ) return NULL ; node = node -> parent ; level -- ; } node = node -> parent -> right ; if ( node == NULL ) return NULL ; while ( level < 0 ) { if ( node -> left != NULL ) node = node -> left ; else if ( node -> right != NULL ) node = node -> right ; else break ; level ++ ; } if ( level == 0 ) return node ; return findRightSibling ( node , level ) ; } int main ( ) { Node * root = newNode ( 1 , NULL ) ; root -> left = newNode ( 2 , root ) ; root -> right = newNode ( 3 , root ) ; root -> left -> left = newNode ( 4 , root -> left ) ; root -> left -> right = newNode ( 6 , root -> left ) ; root -> left -> left -> left = newNode ( 7 , root -> left -> left ) ; root -> left -> left -> left -> left = newNode ( 10 , root -> left -> left -> left ) ; root -> left -> right -> right = newNode ( 9 , root -> left -> right ) ; root -> right -> right = newNode ( 5 , root -> right ) ; root -> right -> right -> right = newNode ( 8 , root -> right -> right ) ; root -> right -> right -> right -> right = newNode ( 12 , root -> right -> right -> right ) ; Node * res = findRightSibling ( root -> left -> left -> left -> left , 0 ) ; if ( res == NULL ) printf ( " No ▁ right ▁ sibling " ) ; else printf ( " % d " , res -> data ) ; return 0 ; }
Find next right node of a given key | Set 2 | C ++ program to find next right of a given key using preorder traversal ; A Binary Tree Node ; Utility function to create a new tree node ; Function to find next node for given node in same level in a binary tree by using pre - order traversal ; return null if tree is empty ; if desired node is found , set value_level to current level ; if value_level is already set , then current node is the next right node ; recurse for left subtree by increasing level by 1 ; if node is found in left subtree , return it ; recurse for right subtree by increasing level by 1 ; Function to find next node of given node in the same level in given binary tree ; A utility function to test above functions ; Driver program to test above functions ; Let us create binary tree given in the above example
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { struct Node * left , * right ; int key ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return temp ; } Node * nextRightNode ( Node * root , int k , int level , int & value_level ) { if ( root == NULL ) return NULL ; if ( root -> key == k ) { value_level = level ; return NULL ; } else if ( value_level ) { if ( level == value_level ) return root ; } Node * leftNode = nextRightNode ( root -> left , k , level + 1 , value_level ) ; if ( leftNode ) return leftNode ; return nextRightNode ( root -> right , k , level + 1 , value_level ) ; } Node * nextRightNodeUtil ( Node * root , int k ) { int value_level = 0 ; return nextRightNode ( root , k , 1 , value_level ) ; } void test ( Node * root , int k ) { Node * nr = nextRightNodeUtil ( root , k ) ; if ( nr != NULL ) cout << " Next ▁ Right ▁ of ▁ " << k << " ▁ is ▁ " << nr -> key << endl ; else cout << " No ▁ next ▁ right ▁ node ▁ found ▁ for ▁ " << k << endl ; } int main ( ) { Node * root = newNode ( 10 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 6 ) ; root -> right -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 8 ) ; root -> left -> right = newNode ( 4 ) ; test ( root , 10 ) ; test ( root , 2 ) ; test ( root , 6 ) ; test ( root , 5 ) ; test ( root , 8 ) ; test ( root , 4 ) ; return 0 ; }
Top three elements in binary tree | CPP program to find largest three elements in a binary tree . ; Helper function that allocates a new Node with the given data and NULL left and right pointers . ; function to find three largest element ; if data is greater than first large number update the top three list ; if data is greater than second large number and not equal to first update the bottom two list ; if data is greater than third large number and not equal to first & second update the third highest list ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } void threelargest ( Node * root , int & first , int & second , int & third ) { if ( root == NULL ) return ; if ( root -> data > first ) { third = second ; second = first ; first = root -> data ; } else if ( root -> data > second && root -> data != first ) { third = second ; second = root -> data ; } else if ( root -> data > third && root -> data != first && root -> data != second ) third = root -> data ; threelargest ( root -> left , first , second , third ) ; threelargest ( root -> right , first , second , third ) ; } int main ( ) { struct 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 ( 4 ) ; root -> right -> right = newNode ( 5 ) ; int first = 0 , second = 0 , third = 0 ; threelargest ( root , first , second , third ) ; cout << " three ▁ largest ▁ elements ▁ are ▁ " << first << " ▁ " << second << " ▁ " << third ; return 0 ; }
Find maximum ( or minimum ) in Binary Tree | C ++ program to find maximum and minimum in a Binary Tree ; A tree node ; Constructor that allocates a new node with the given data and NULL left and right pointers . ; Returns maximum value in a given Binary Tree ; Base case ; Return maximum of 3 values : 1 ) Root 's data 2) Max in Left Subtree 3) Max in right subtree ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE #include <iostream> NEW_LINE using namespace std ; class Node { public : int data ; Node * left , * right ; Node ( int data ) { this -> data = data ; this -> left = NULL ; this -> right = NULL ; } } ; int findMax ( Node * root ) { if ( root == NULL ) return INT_MIN ; int res = root -> data ; int lres = findMax ( root -> left ) ; int rres = findMax ( root -> right ) ; if ( lres > res ) res = lres ; if ( rres > res ) res = rres ; return res ; } int main ( ) { Node * NewRoot = NULL ; Node * root = new Node ( 2 ) ; root -> left = new Node ( 7 ) ; root -> right = new Node ( 5 ) ; root -> left -> right = new Node ( 6 ) ; root -> left -> right -> left = new Node ( 1 ) ; root -> left -> right -> right = new Node ( 11 ) ; root -> right -> right = new Node ( 9 ) ; root -> right -> right -> left = new Node ( 4 ) ; cout << " Maximum ▁ element ▁ is ▁ " << findMax ( root ) << endl ; return 0 ; }
Extract Leaves of a Binary Tree in a Doubly Linked List | C ++ program to extract leaves of a Binary Tree in a Doubly Linked List ; Structure for tree and linked list ; Main function which extracts all leaves from given Binary Tree . The function returns new root of Binary Tree ( Note that root may changeif Binary Tree has only one node ) . The function also sets * head_ref as head of doubly linked list . left pointer of tree is used as prev in DLL and right pointer is used as next ; Utility function for allocating node for Binary Tree . ; Utility function for printing tree in In - Order . ; Utility function for printing double linked list . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; class Node { public : int data ; Node * left , * right ; } ; Node * extractLeafList ( Node * root , Node * * head_ref ) { if ( root == NULL ) return NULL ; if ( root -> left == NULL && root -> right == NULL ) { root -> right = * head_ref ; if ( * head_ref != NULL ) ( * head_ref ) -> left = root ; * head_ref = root ; return NULL ; } root -> right = extractLeafList ( root -> right , head_ref ) ; root -> left = extractLeafList ( root -> left , head_ref ) ; return root ; } Node * newNode ( int data ) { Node * node = new Node ( ) ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } void print ( Node * root ) { if ( root != NULL ) { print ( root -> left ) ; cout << root -> data << " ▁ " ; print ( root -> right ) ; } } void printList ( Node * head ) { while ( head ) { cout << head -> data << " ▁ " ; head = head -> right ; } } int main ( ) { Node * head = NULL ; Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; root -> left -> left -> left = newNode ( 7 ) ; root -> left -> left -> right = newNode ( 8 ) ; root -> right -> right -> left = newNode ( 9 ) ; root -> right -> right -> right = newNode ( 10 ) ; cout << " Inorder ▁ Trvaersal ▁ of ▁ given ▁ Tree ▁ is : STRNEWLINE " ; print ( root ) ; root = extractLeafList ( root , & head ) ; cout << " Extracted Double Linked list is : " ; printList ( head ) ; cout << " Inorder traversal of modified tree is : " print ( root ) ; return 0 ; }
Inorder Successor of a node in Binary Tree | C ++ Program to find inorder successor . ; structure of a Binary Node . ; Function to create a new Node . ; function that prints the inorder successor of a target node . next will point the last tracked node , which will be the answer . ; if root is null then return ; if target node found then enter this condition ; Driver Code ; Let 's construct the binary tree   as shown in above diagram. ; Case 1 ; case 2 ; case 3
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left ; Node * right ; } ; Node * newNode ( int val ) { Node * temp = new Node ; temp -> data = val ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } void inorderSuccessor ( Node * root , Node * target_node , Node * & next ) { if ( ! root ) return ; inorderSuccessor ( root -> right , target_node , next ) ; if ( root -> data == target_node -> data ) { if ( next == NULL ) cout << " inorder ▁ successor ▁ of ▁ " << root -> data << " ▁ is : ▁ null STRNEWLINE " ; else cout << " inorder ▁ successor ▁ of ▁ " << root -> data << " ▁ is : ▁ " << next -> data << " STRNEWLINE " ; } next = root ; inorderSuccessor ( root -> left , target_node , next ) ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; Node * next = NULL ; inorderSuccessor ( root , root -> right , next ) ; next = NULL ; inorderSuccessor ( root , root -> left -> left , next ) ; next = NULL ; inorderSuccessor ( root , root -> right -> right , next ) ; return 0 ; }