codeparrot/xlcost-text-to-code huggingface dataset:
Check if two BSTs contain same set of elements | CPP program to check if two BSTs contains same set of elements ; BST Node ; Utility function to create new Node ; function to insert elements of the tree to map m ; function to check if the two BSTs contain same set of elements ; Base cases ; Create two hash sets and store elements both BSTs in them . ; Return true if both hash sets contain same elements . ; Driver program to check above functions ; First BST ; Second BST ; check if two BSTs have same set of elements
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; Node * newNode ( int val ) { Node * temp = new Node ; temp -> data = val ; temp -> left = temp -> right = NULL ; return temp ; } void insertToHash ( Node * root , unordered_set < int > & s ) { if ( ! root ) return ; insertToHash ( root -> left , s ) ; s . insert ( root -> data ) ; insertToHash ( root -> right , s ) ; } bool checkBSTs ( Node * root1 , Node * root2 ) { if ( ! root1 && ! root2 ) return true ; if ( ( root1 && ! root2 ) || ( ! root1 && root2 ) ) return false ; unordered_set < int > s1 , s2 ; insertToHash ( root1 , s1 ) ; insertToHash ( root2 , s2 ) ; return ( s1 == s2 ) ; } int main ( ) { Node * root1 = newNode ( 15 ) ; root1 -> left = newNode ( 10 ) ; root1 -> right = newNode ( 20 ) ; root1 -> left -> left = newNode ( 5 ) ; root1 -> left -> right = newNode ( 12 ) ; root1 -> right -> right = newNode ( 25 ) ; Node * root2 = newNode ( 15 ) ; root2 -> left = newNode ( 12 ) ; root2 -> right = newNode ( 20 ) ; root2 -> left -> left = newNode ( 5 ) ; root2 -> left -> left -> right = newNode ( 10 ) ; root2 -> right -> right = newNode ( 25 ) ; if ( checkBSTs ( root1 , root2 ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }
Check if two BSTs contain same set of elements | CPP program to check if two BSTs contains same set of elements ; BST Node ; Utility function to create new Node ; function to insert elements of the tree to map m ; function to check if the two BSTs contain same set of elements ; Base cases ; Create two vectors and store inorder traversals of both BSTs in them . ; Return true if both vectors are identical ; Driver program to check above functions ; First BST ; Second BST ; check if two BSTs have same set of elements
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; Node * newNode ( int val ) { Node * temp = new Node ; temp -> data = val ; temp -> left = temp -> right = NULL ; return temp ; } void storeInorder ( Node * root , vector < int > & v ) { if ( ! root ) return ; storeInorder ( root -> left , v ) ; v . push_back ( root -> data ) ; storeInorder ( root -> right , v ) ; } bool checkBSTs ( Node * root1 , Node * root2 ) { if ( ! root1 && ! root2 ) return true ; if ( ( root1 && ! root2 ) || ( ! root1 && root2 ) ) return false ; vector < int > v1 , v2 ; storeInorder ( root1 , v1 ) ; storeInorder ( root2 , v2 ) ; return ( v1 == v2 ) ; } int main ( ) { Node * root1 = newNode ( 15 ) ; root1 -> left = newNode ( 10 ) ; root1 -> right = newNode ( 20 ) ; root1 -> left -> left = newNode ( 5 ) ; root1 -> left -> right = newNode ( 12 ) ; root1 -> right -> right = newNode ( 25 ) ; Node * root2 = newNode ( 15 ) ; root2 -> left = newNode ( 12 ) ; root2 -> right = newNode ( 20 ) ; root2 -> left -> left = newNode ( 5 ) ; root2 -> left -> left -> right = newNode ( 10 ) ; root2 -> right -> right = newNode ( 25 ) ; if ( checkBSTs ( root1 , root2 ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }
Shortest distance between two nodes in BST | CPP program to find distance between two nodes in BST ; Standard BST insert function ; This function returns distance of x from root . This function assumes that x exists in BST and BST is not NULL . ; Returns minimum distance between a and b . This function assumes that a and b exist in BST . ; Both keys lie in left ; Both keys lie in right same path ; Lie in opposite directions ( Root is LCA of two nodes ) ; This function make sure that a is smaller than b before making a call to findDistWrapper ( ) ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { struct Node * left , * right ; int key ; } ; struct Node * newNode ( int key ) { struct Node * ptr = new Node ; ptr -> key = key ; ptr -> left = ptr -> right = NULL ; return ptr ; } struct Node * insert ( struct Node * root , int key ) { if ( ! root ) root = newNode ( key ) ; else if ( root -> key > key ) root -> left = insert ( root -> left , key ) ; else if ( root -> key < key ) root -> right = insert ( root -> right , key ) ; return root ; } int distanceFromRoot ( struct Node * root , int x ) { if ( root -> key == x ) return 0 ; else if ( root -> key > x ) return 1 + distanceFromRoot ( root -> left , x ) ; return 1 + distanceFromRoot ( root -> right , x ) ; } int distanceBetween2 ( struct Node * root , int a , int b ) { if ( ! root ) return 0 ; if ( root -> key > a && root -> key > b ) return distanceBetween2 ( root -> left , a , b ) ; if ( root -> key < a && root -> key < b ) return distanceBetween2 ( root -> right , a , b ) ; if ( root -> key >= a && root -> key <= b ) return distanceFromRoot ( root , a ) + distanceFromRoot ( root , b ) ; } int findDistWrapper ( Node * root , int a , int b ) { if ( a > b ) swap ( a , b ) ; return distanceBetween2 ( root , a , b ) ; } int main ( ) { struct Node * root = NULL ; root = insert ( root , 20 ) ; insert ( root , 10 ) ; insert ( root , 5 ) ; insert ( root , 15 ) ; insert ( root , 30 ) ; insert ( root , 25 ) ; insert ( root , 35 ) ; int a = 5 , b = 55 ; cout << findDistWrapper ( root , 5 , 35 ) ; return 0 ; }
Print BST keys in given Range | O ( 1 ) Space | CPP code to print BST keys in given Range in constant space using Morris traversal . ; Function to print the keys in range ; check if current node lies between n1 and n2 ; finding the inorder predecessor - inorder predecessor is the right most in left subtree or the left child , i . e in BST it is the maximum ( right most ) in left subtree . ; check if current node lies between n1 and n2 ; Helper function to create a new node ; Driver Code ; Constructed binary tree is 4 / \ 2 7 / \ / \ 1 3 6 10
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct node { int data ; struct node * left , * right ; } ; void RangeTraversal ( node * root , int n1 , int n2 ) { if ( ! root ) return ; node * curr = root ; while ( curr ) { if ( curr -> left == NULL ) { if ( curr -> data <= n2 && curr -> data >= n1 ) { cout << curr -> data << " ▁ " ; } curr = curr -> right ; } else { node * pre = curr -> left ; while ( pre -> right != NULL && pre -> right != curr ) pre = pre -> right ; if ( pre -> right == NULL ) { pre -> right = curr ; curr = curr -> left ; } else { pre -> right = NULL ; if ( curr -> data <= n2 && curr -> data >= n1 ) { cout << curr -> data << " ▁ " ; } curr = curr -> right ; } } } } node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> right = temp -> left = NULL ; return temp ; } int main ( ) { node * root = newNode ( 4 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 7 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 10 ) ; RangeTraversal ( root , 4 , 12 ) ; return 0 ; }
Count BST subtrees that lie in given range | C ++ program to count subtrees that lie in a given range ; A BST node ; A utility function to check if data of root is in range from low to high ; A recursive function to get count of nodes whose subtree is in range from low to hgih . This function returns true if nodes in subtree rooted under ' root ' are in range . ; Base case ; Recur for left and right subtrees ; If both left and right subtrees are in range and current node is also in range , then increment count and return true ; A wrapper over getCountUtil ( ) . This function initializes count as 0 and calls getCountUtil ( ) ; Utility function to create new node ; Driver program ; Let us construct the BST shown in the above figure ; Let us constructed BST shown in above example 10 / \ 5 50 / / \ 1 40 100
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct node { int data ; struct node * left , * right ; } ; bool inRange ( node * root , int low , int high ) { return root -> data >= low && root -> data <= high ; } bool getCountUtil ( node * root , int low , int high , int * count ) { if ( root == NULL ) return true ; bool l = getCountUtil ( root -> left , low , high , count ) ; bool r = getCountUtil ( root -> right , low , high , count ) ; if ( l && r && inRange ( root , low , high ) ) { ++ * count ; return true ; } return false ; } int getCount ( node * root , int low , int high ) { int count = 0 ; getCountUtil ( root , low , high , & count ) ; return count ; } node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return ( temp ) ; } int main ( ) { node * root = newNode ( 10 ) ; root -> left = newNode ( 5 ) ; root -> right = newNode ( 50 ) ; root -> left -> left = newNode ( 1 ) ; root -> right -> left = newNode ( 40 ) ; root -> right -> right = newNode ( 100 ) ; int l = 5 ; int h = 45 ; cout << " Count ▁ of ▁ subtrees ▁ in ▁ [ " << l << " , ▁ " << h << " ] ▁ is ▁ " << getCount ( root , l , h ) ; return 0 ; }
Remove all leaf nodes from the binary search tree | C ++ program to delete leaf Node from binary search tree . ; Create a newNode in binary search tree . ; Insert a Node in binary search tree . ; Function for inorder traversal in a BST . ; Delete leaf nodes from binary search tree . ; Else recursively delete in left and right subtrees . ; Driver code
#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 * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } struct Node * insert ( struct Node * root , int data ) { if ( root == NULL ) return newNode ( data ) ; if ( data < root -> data ) root -> left = insert ( root -> left , data ) ; else if ( data > root -> data ) root -> right = insert ( root -> right , data ) ; return root ; } void inorder ( struct Node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; cout << root -> data << " ▁ " ; inorder ( root -> right ) ; } } struct Node * leafDelete ( struct Node * root ) { if ( root == NULL ) return NULL ; if ( root -> left == NULL && root -> right == NULL ) { free ( root ) ; return NULL ; } root -> left = leafDelete ( root -> left ) ; root -> right = leafDelete ( root -> right ) ; return root ; } int main ( ) { struct Node * root = NULL ; root = insert ( root , 20 ) ; insert ( root , 10 ) ; insert ( root , 5 ) ; insert ( root , 15 ) ; insert ( root , 30 ) ; insert ( root , 25 ) ; insert ( root , 35 ) ; cout << " Inorder ▁ before ▁ Deleting ▁ the ▁ leaf ▁ Node . " << endl ; inorder ( root ) ; cout << endl ; leafDelete ( root ) ; cout << " INorder ▁ after ▁ Deleting ▁ the ▁ leaf ▁ Node . " << endl ; inorder ( root ) ; return 0 ; }
Sum of k smallest elements in BST | c ++ program to find Sum Of All Elements smaller than or equal to Kth Smallest Element In BST ; Binary tree Node ; utility function new Node of BST ; A utility function to insert a new Node with given key in BST and also maintain lcount , Sum ; If the tree is empty , return a new Node ; Otherwise , recur down the tree ; return the ( unchanged ) Node pointer ; function return sum of all element smaller than and equal to Kth smallest element ; Base cases ; Compute sum of elements in left subtree ; Add root 's data ; Add current Node ; If count is less than k , return right subtree Nodes ; Wrapper over ksmallestElementSumRec ( ) ; Driver program to test above functions ; 20 / \ 8 22 / \ 4 12 / \ 10 14
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left , * right ; } ; struct Node * createNode ( int data ) { Node * new_Node = new Node ; new_Node -> left = NULL ; new_Node -> right = NULL ; new_Node -> data = data ; return new_Node ; } struct Node * insert ( Node * root , int key ) { if ( root == NULL ) return createNode ( key ) ; if ( root -> data > key ) root -> left = insert ( root -> left , key ) ; else if ( root -> data < key ) root -> right = insert ( root -> right , key ) ; return root ; } int ksmallestElementSumRec ( Node * root , int k , int & count ) { if ( root == NULL ) return 0 ; if ( count > k ) return 0 ; int res = ksmallestElementSumRec ( root -> left , k , count ) ; if ( count >= k ) return res ; res += root -> data ; count ++ ; if ( count >= k ) return res ; return res + ksmallestElementSumRec ( root -> right , k , count ) ; } int ksmallestElementSum ( struct Node * root , int k ) { int count = 0 ; ksmallestElementSumRec ( root , k , count ) ; } int main ( ) { Node * root = NULL ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 4 ) ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 14 ) ; root = insert ( root , 22 ) ; int k = 3 ; cout << ksmallestElementSum ( root , k ) << endl ; return 0 ; }
Sum of k smallest elements in BST | C ++ program to find Sum Of All Elements smaller than or equal t Kth Smallest Element In BST ; Binary tree Node ; utility function new Node of BST ; A utility function to insert a new Node with given key in BST and also maintain lcount , Sum ; If the tree is empty , return a new Node ; Otherwise , recur down the tree ; increment lCount of current Node ; increment current Node sum by adding key into it ; return the ( unchanged ) Node pointer ; function return sum of all element smaller than and equal to Kth smallest element ; if we fount k smallest element then break the function ; store sum of all element smaller than current root ; ; decremented k and call right sub - tree ; call left sub - tree ; Wrapper over ksmallestElementSumRec ( ) ; Driver program to test above functions ; 20 / \ 8 22 / \ 4 12 / \ 10 14
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; int lCount ; int Sum ; Node * left ; Node * right ; } ; struct Node * createNode ( int data ) { Node * new_Node = new Node ; new_Node -> left = NULL ; new_Node -> right = NULL ; new_Node -> data = data ; new_Node -> lCount = 0 ; new_Node -> Sum = 0 ; return new_Node ; } struct Node * insert ( Node * root , int key ) { if ( root == NULL ) return createNode ( key ) ; if ( root -> data > key ) { root -> lCount ++ ; root -> Sum += key ; root -> left = insert ( root -> left , key ) ; } else if ( root -> data < key ) root -> right = insert ( root -> right , key ) ; return root ; } void ksmallestElementSumRec ( Node * root , int k , int & temp_sum ) { if ( root == NULL ) return ; if ( ( root -> lCount + 1 ) == k ) { temp_sum += root -> data + root -> Sum ; return ; } else if ( k > root -> lCount ) { temp_sum += root -> data + root -> Sum ; k = k - ( root -> lCount + 1 ) ; ksmallestElementSumRec ( root -> right , k , temp_sum ) ; } else ksmallestElementSumRec ( root -> left , k , temp_sum ) ; } int ksmallestElementSum ( struct Node * root , int k ) { int sum = 0 ; ksmallestElementSumRec ( root , k , sum ) ; return sum ; } int main ( ) { Node * root = NULL ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 4 ) ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 14 ) ; root = insert ( root , 22 ) ; int k = 3 ; cout << ksmallestElementSum ( root , k ) << endl ; return 0 ; }
Inorder predecessor and successor for a given key in BST |
struct Node { int key ; struct Node * left , * right ; } ;
Inorder predecessor and successor for a given key in BST | CPP code for inorder successor and predecessor of tree ; Function to return data ; since inorder traversal results in ascending order visit to node , we can store the values of the largest no which is smaller than a ( predecessor ) and smallest no which is large than a ( successor ) using inorder traversal ; If root is null return ; traverse the left subtree ; root data is greater than a ; q stores the node whose data is greater than a and is smaller than the previously stored data in * q which is successor ; if the root data is smaller than store it in p which is predecessor ; traverse the right subtree ; Driver code
#include <iostream> NEW_LINE #include <stdlib.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getnode ( int info ) { Node * p = ( Node * ) malloc ( sizeof ( Node ) ) ; p -> data = info ; p -> right = NULL ; p -> left = NULL ; return p ; } void find_p_s ( Node * root , int a , Node * * p , Node * * q ) { if ( ! root ) return ; find_p_s ( root -> left , a , p , q ) ; if ( root && root -> data > a ) { if ( ( ! * q ) || ( * q ) && ( * q ) -> data > root -> data ) * q = root ; } else if ( root && root -> data < a ) { * p = root ; } find_p_s ( root -> right , a , p , q ) ; } int main ( ) { Node * root1 = getnode ( 50 ) ; root1 -> left = getnode ( 20 ) ; root1 -> right = getnode ( 60 ) ; root1 -> left -> left = getnode ( 10 ) ; root1 -> left -> right = getnode ( 30 ) ; root1 -> right -> left = getnode ( 55 ) ; root1 -> right -> right = getnode ( 70 ) ; Node * p = NULL , * q = NULL ; find_p_s ( root1 , 55 , & p , & q ) ; if ( p ) cout << p -> data ; if ( q ) cout << " ▁ " << q -> data ; return 0 ; }
Inorder predecessor and successor for a given key in BST | Iterative Approach | C ++ program to find predecessor and successor in a BST ; BST Node ; Function that finds predecessor and successor of key in BST . ; Search for given key in BST . ; If root is given key . ; the minimum value in right subtree is predecessor . ; the maximum value in left subtree is successor . ; If key is greater than root , then key lies in right subtree . Root could be predecessor if left subtree of key is null . ; If key is smaller than root , then key lies in left subtree . Root could be successor if right subtree of key is null . ; A utility function to create a new BST node ; A utility function to insert a new node with given key in BST ; Driver program to test above function ; Key to be searched in BST ; Let us create following BST 50 / \ / \ 30 70 / \ / \ / \ / \ 20 40 60 80
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int key ; struct Node * left , * right ; } ; void findPreSuc ( Node * root , Node * & pre , Node * & suc , int key ) { if ( root == NULL ) return ; while ( root != NULL ) { if ( root -> key == key ) { if ( root -> right ) { suc = root -> right ; while ( suc -> left ) suc = suc -> left ; } if ( root -> left ) { pre = root -> left ; while ( pre -> right ) pre = pre -> right ; } return ; } else if ( root -> key < key ) { pre = root ; root = root -> right ; } else { suc = root ; root = root -> left ; } } } Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } 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 ; } int main ( ) { int key = 65 ; Node * root = NULL ; root = insert ( root , 50 ) ; insert ( root , 30 ) ; insert ( root , 20 ) ; insert ( root , 40 ) ; insert ( root , 70 ) ; insert ( root , 60 ) ; insert ( root , 80 ) ; Node * pre = NULL , * suc = NULL ; findPreSuc ( root , pre , suc , key ) ; if ( pre != NULL ) cout << " Predecessor ▁ is ▁ " << pre -> key << endl ; else cout << " - 1" ; if ( suc != NULL ) cout << " Successor ▁ is ▁ " << suc -> key ; else cout << " - 1" ; return 0 ; }
Find a pair with given sum in BST | CPP program to find a pair with given sum using hashing ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * NewNode ( int data ) { Node * temp = ( Node * ) malloc ( sizeof ( Node ) ) ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } Node * insert ( Node * root , int key ) { if ( root == NULL ) return NewNode ( key ) ; if ( key < root -> data ) root -> left = insert ( root -> left , key ) ; else root -> right = insert ( root -> right , key ) ; return root ; } bool findpairUtil ( Node * root , int sum , unordered_set < int > & set ) { if ( root == NULL ) return false ; if ( findpairUtil ( root -> left , sum , set ) ) return true ; if ( set . find ( sum - root -> data ) != set . end ( ) ) { cout << " Pair ▁ is ▁ found ▁ ( " << sum - root -> data << " , ▁ " << root -> data << " ) " << endl ; return true ; } else set . insert ( root -> data ) ; return findpairUtil ( root -> right , sum , set ) ; } void findPair ( Node * root , int sum ) { unordered_set < int > set ; if ( ! findpairUtil ( root , sum , set ) ) cout << " Pairs ▁ do ▁ not ▁ exit " << endl ; } int main ( ) { Node * root = NULL ; root = insert ( root , 15 ) ; root = insert ( root , 10 ) ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 12 ) ; root = insert ( root , 16 ) ; root = insert ( root , 25 ) ; root = insert ( root , 10 ) ; int sum = 33 ; findPair ( root , sum ) ; return 0 ; }
Find pairs with given sum such that pair elements lie in different BSTs | C ++ program to find pairs with given sum such that one element of pair exists in one BST and other in other BST . ; A binary Tree node ; A utility function to create a new BST node with key as given num ; A utility function to insert a given key to BST ; store storeInorder traversal in auxiliary array ; Function to find pair for given sum in different bst vect1 [ ] -- > stores storeInorder traversal of first bst vect2 [ ] -- > stores storeInorder traversal of second bst ; Initialize two indexes to two different corners of two vectors . ; find pair by moving two corners . ; If we found a pair ; If sum is more , move to higher value in first vector . ; If sum is less , move to lower value in second vector . ; Prints all pairs with given " sum " such that one element of pair is in tree with root1 and other node is in tree with root2 . ; Store inorder traversals of two BSTs in two vectors . ; Now the problem reduces to finding a pair with given sum such that one element is in vect1 and other is in vect2 . ; Driver program to run the case ; first BST ; second BST
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int num ) { struct Node * temp = new Node ; temp -> data = num ; temp -> left = temp -> right = NULL ; return temp ; } 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 ; } void storeInorder ( Node * ptr , vector < int > & vect ) { if ( ptr == NULL ) return ; storeInorder ( ptr -> left , vect ) ; vect . push_back ( ptr -> data ) ; storeInorder ( ptr -> right , vect ) ; } void pairSumUtil ( vector < int > & vect1 , vector < int > & vect2 , int sum ) { int left = 0 ; int right = vect2 . size ( ) - 1 ; while ( left < vect1 . size ( ) && right >= 0 ) { if ( vect1 [ left ] + vect2 [ right ] == sum ) { cout << " ( " << vect1 [ left ] << " , ▁ " << vect2 [ right ] << " ) , ▁ " ; left ++ ; right -- ; } else if ( vect1 [ left ] + vect2 [ right ] < sum ) left ++ ; else right -- ; } } void pairSum ( Node * root1 , Node * root2 , int sum ) { vector < int > vect1 , vect2 ; storeInorder ( root1 , vect1 ) ; storeInorder ( root2 , vect2 ) ; pairSumUtil ( vect1 , vect2 , sum ) ; } int main ( ) { struct 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 ) ; struct 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 ) ; return 0 ; }