codeparrot/xlcost-text-to-code huggingface dataset:
Sum of leaf nodes at minimum level | C ++ implementation to find the sum of leaf nodes at minimum level ; structure of a node of binary tree ; function to get a new node ; allocate space ; put in the data ; function to find the sum of leaf nodes at minimum level ; if tree is empty ; if there is only one node ; queue used for level order traversal ; push root node in the queue ' q ' ; count number of nodes in the current level ; traverse the current level nodes ; get front element from ' q ' ; if it is a leaf node ; accumulate data to ' sum ' ; set flag ' f ' to 1 , to signify minimum level for leaf nodes has been encountered ; if top ' s ▁ left ▁ and ▁ right ▁ child ▁ ▁ ▁ exists , ▁ then ▁ push ▁ them ▁ to ▁ ' q ' ; required sum ; Driver program to test above ; binary tree creation
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getNode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return newNode ; } int sumOfLeafNodesAtMinLevel ( Node * root ) { if ( ! root ) return 0 ; if ( ! root -> left && ! root -> right ) return root -> data ; queue < Node * > q ; int sum = 0 ; bool f = 0 ; q . push ( root ) ; while ( f == 0 ) { int nc = q . size ( ) ; while ( nc -- ) { Node * top = q . front ( ) ; q . pop ( ) ; if ( ! top -> left && ! top -> right ) { sum += top -> data ; f = 1 ; } else { if ( top -> left ) q . push ( top -> left ) ; if ( top -> right ) q . push ( top -> right ) ; } } } return sum ; } int main ( ) { Node * root = getNode ( 1 ) ; root -> left = getNode ( 2 ) ; root -> right = getNode ( 3 ) ; root -> left -> left = getNode ( 4 ) ; root -> left -> right = getNode ( 5 ) ; root -> right -> left = getNode ( 6 ) ; root -> right -> right = getNode ( 7 ) ; root -> left -> right -> left = getNode ( 8 ) ; root -> right -> left -> right = getNode ( 9 ) ; cout << " Sum ▁ = ▁ " << sumOfLeafNodesAtMinLevel ( root ) ; return 0 ; }
Root to leaf path sum equal to a given number |  ; A binary tree node has data , pointer to left child and a pointer to right child ; Given a tree and a sum , return true if there is a path from the root down to a leaf , such that adding up all the values along the path equals the given sum . Strategy : subtract the node value from the sum when recurring down , and check to see if the sum is 0 when you run out of tree . ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Driver Code ; Constructed binary tree is 10 / \ 8 2 / \ / 3 5 2
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define bool  int NEW_LINE class node { public : int data ; node * left ; node * right ; } ; bool hasPathSum ( node * Node , int sum ) { if ( Node == NULL ) { return ( sum == 0 ) ; } else { bool ans = 0 ; int subSum = sum - Node -> data ; if ( subSum == 0 && Node -> left == NULL && Node -> right == NULL ) return 1 ; if ( Node -> left ) ans = ans || hasPathSum ( Node -> left , subSum ) ; if ( Node -> right ) ans = ans || hasPathSum ( Node -> right , subSum ) ; return ans ; } } node * newnode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int main ( ) { int sum = 21 ; node * root = newnode ( 10 ) ; root -> left = newnode ( 8 ) ; root -> right = newnode ( 2 ) ; root -> left -> left = newnode ( 3 ) ; root -> left -> right = newnode ( 5 ) ; root -> right -> left = newnode ( 2 ) ; if ( hasPathSum ( root , sum ) ) cout << " There ▁ is ▁ a ▁ root - to - leaf ▁ path ▁ with ▁ sum ▁ " << sum ; else cout << " There ▁ is ▁ no ▁ root - to - leaf ▁ path ▁ with ▁ sum ▁ " << sum ; return 0 ; }
Sum of all the numbers that are formed from root to leaf paths | C ++ program to find sum of all paths from root to leaves ; function to allocate new node with given data ; Returns sum of all root to leaf paths . The first parameter is root of current subtree , the second parameter is value of the number formed by nodes from root to this node ; Base case ; Update val ; if current node is leaf , return the current value of val ; recur sum of values for left and right subtree ; A wrapper function over treePathsSumUtil ( ) ; Pass the initial value as 0 as there is nothing above root ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; class node { public : int data ; node * left , * right ; } ; node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = Node -> right = NULL ; return ( Node ) ; } int treePathsSumUtil ( node * root , int val ) { if ( root == NULL ) return 0 ; val = ( val * 10 + root -> data ) ; if ( root -> left == NULL && root -> right == NULL ) return val ; return treePathsSumUtil ( root -> left , val ) + treePathsSumUtil ( root -> right , val ) ; } int treePathsSum ( node * root ) { return treePathsSumUtil ( root , 0 ) ; } int main ( ) { node * root = newNode ( 6 ) ; root -> left = newNode ( 3 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 2 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 4 ) ; root -> left -> right -> left = newNode ( 7 ) ; root -> left -> right -> right = newNode ( 4 ) ; cout << " Sum ▁ of ▁ all ▁ paths ▁ is ▁ " << treePathsSum ( root ) ; return 0 ; }
Merge Two Binary Trees by doing Node Sum ( Recursive and Iterative ) | C ++ program to Merge Two Binary Trees ; A binary tree node has data , pointer to left child and a pointer to right child ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Given a binary tree , print its nodes in inorder ; first recur on left child ; then print the data of node ; now recur on right child ; Function to merge given two binary trees ; Driver code ; Let us construct the first Binary Tree 1 / \ 2 3 / \ \ 4 5 6 ; Let us construct the second Binary Tree 4 / \ 1 7 / / \ 3 2 6
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> left = new_node -> right = NULL ; return new_node ; } void inorder ( Node * node ) { if ( ! node ) return ; inorder ( node -> left ) ; printf ( " % d ▁ " , node -> data ) ; inorder ( node -> right ) ; } Node * MergeTrees ( Node * t1 , Node * t2 ) { if ( ! t1 ) return t2 ; if ( ! t2 ) return t1 ; t1 -> data += t2 -> data ; t1 -> left = MergeTrees ( t1 -> left , t2 -> left ) ; t1 -> right = MergeTrees ( t1 -> right , t2 -> right ) ; return t1 ; } int main ( ) { Node * root1 = newNode ( 1 ) ; root1 -> left = newNode ( 2 ) ; root1 -> right = newNode ( 3 ) ; root1 -> left -> left = newNode ( 4 ) ; root1 -> left -> right = newNode ( 5 ) ; root1 -> right -> right = newNode ( 6 ) ; Node * root2 = newNode ( 4 ) ; root2 -> left = newNode ( 1 ) ; root2 -> right = newNode ( 7 ) ; root2 -> left -> left = newNode ( 3 ) ; root2 -> right -> left = newNode ( 2 ) ; root2 -> right -> right = newNode ( 6 ) ; Node * root3 = MergeTrees ( root1 , root2 ) ; printf ( " The ▁ Merged ▁ Binary ▁ Tree ▁ is : STRNEWLINE " ) ; inorder ( root3 ) ; return 0 ; }
Merge Two Binary Trees by doing Node Sum ( Recursive and Iterative ) | C ++ program to Merge Two Binary Trees ; A binary tree node has data , pointer to left child and a pointer to right child ; Structure to store node pair onto stack ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Given a binary tree , print its nodes in inorder ; first recur on left child ; then print the data of node ; now recur on right child ; Function to merge given two binary trees ; Driver code ; Let us construct the first Binary Tree 1 / \ 2 3 / \ \ 4 5 6 ; Let us construct the second Binary Tree 4 / \ 1 7 / / \ 3 2 6
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct snode { Node * l , * r ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> left = new_node -> right = NULL ; return new_node ; } void inorder ( Node * node ) { if ( ! node ) return ; inorder ( node -> left ) ; printf ( " % d ▁ " , node -> data ) ; inorder ( node -> right ) ; } Node * MergeTrees ( Node * t1 , Node * t2 ) { if ( ! t1 ) return t2 ; if ( ! t2 ) return t1 ; stack < snode > s ; snode temp ; temp . l = t1 ; temp . r = t2 ; s . push ( temp ) ; snode n ; while ( ! s . empty ( ) ) { n = s . top ( ) ; s . pop ( ) ; if ( n . l == NULL n . r == NULL ) continue ; n . l -> data += n . r -> data ; if ( n . l -> left == NULL ) n . l -> left = n . r -> left ; else { snode t ; t . l = n . l -> left ; t . r = n . r -> left ; s . push ( t ) ; } if ( n . l -> right == NULL ) n . l -> right = n . r -> right ; else { snode t ; t . l = n . l -> right ; t . r = n . r -> right ; s . push ( t ) ; } } return t1 ; } int main ( ) { Node * root1 = newNode ( 1 ) ; root1 -> left = newNode ( 2 ) ; root1 -> right = newNode ( 3 ) ; root1 -> left -> left = newNode ( 4 ) ; root1 -> left -> right = newNode ( 5 ) ; root1 -> right -> right = newNode ( 6 ) ; Node * root2 = newNode ( 4 ) ; root2 -> left = newNode ( 1 ) ; root2 -> right = newNode ( 7 ) ; root2 -> left -> left = newNode ( 3 ) ; root2 -> right -> left = newNode ( 2 ) ; root2 -> right -> right = newNode ( 6 ) ; Node * root3 = MergeTrees ( root1 , root2 ) ; printf ( " The ▁ Merged ▁ Binary ▁ Tree ▁ is : STRNEWLINE " ) ; inorder ( root3 ) ; return 0 ; }
Find root of the tree where children id sum for every node is given | Find root of tree where children sum for every node id is given . ; Every node appears once as an id , and every node except for the root appears once in a sum . So if we subtract all the sums from all the ids , we 're left  with the root id. ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findRoot ( pair < int , int > arr [ ] , int n ) { int root = 0 ; for ( int i = 0 ; i < n ; i ++ ) root += ( arr [ i ] . first - arr [ i ] . second ) ; return root ; } int main ( ) { pair < int , int > arr [ ] = { { 1 , 5 } , { 2 , 0 } , { 3 , 0 } , { 4 , 0 } , { 5 , 5 } , { 6 , 5 } } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " % d STRNEWLINE " , findRoot ( arr , n ) ) ; return 0 ; }
Print Postorder traversal from given Inorder and Preorder traversals | C ++ program to print postorder traversal from preorder and inorder traversals ; A utility function to search x in arr [ ] of size n ; Prints postorder traversal from given inorder and preorder traversals ; The first element in pre [ ] is always root , search it in in [ ] to find left and right subtrees ; If left subtree is not empty , print left subtree ; If right subtree is not empty , print right subtree ; Print root ; Driver program to test above functions
#include <iostream> NEW_LINE using namespace std ; int search ( int arr [ ] , int x , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == x ) return i ; return -1 ; } void printPostOrder ( int in [ ] , int pre [ ] , int n ) { int root = search ( in , pre [ 0 ] , n ) ; if ( root != 0 ) printPostOrder ( in , pre + 1 , root ) ; if ( root != n - 1 ) printPostOrder ( in + root + 1 , pre + root + 1 , n - root - 1 ) ; cout << pre [ 0 ] << " ▁ " ; } int main ( ) { int in [ ] = { 4 , 2 , 5 , 1 , 3 , 6 } ; int pre [ ] = { 1 , 2 , 4 , 5 , 3 , 6 } ; int n = sizeof ( in ) / sizeof ( in [ 0 ] ) ; cout << " Postorder ▁ traversal ▁ " << endl ; printPostOrder ( in , pre , n ) ; return 0 ; }
Lowest Common Ancestor in a Binary Tree | Set 1 | C ++ Program to find LCA of n1 and n2 using one traversal of Binary Tree ; A Binary Tree Node ; Utility function to create a new tree Node ; This function returns pointer to LCA of two given values n1 and n2 . This function assumes that n1 and n2 are present in Binary Tree ; Base case ; If either n1 or n2 matches with root 's key, report  the presence by returning root (Note that if a key is  ancestor of other, then the ancestor key becomes LCA ; Look for keys in left and right subtrees ; If both of the above calls return Non - NULL , then one key is present in once subtree and other is present in other , So this node is the LCA ; Otherwise check if left subtree or right subtree is LCA ; Driver program to test above functions
#include <iostream> 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 ; } struct Node * findLCA ( struct Node * root , int n1 , int n2 ) { if ( root == NULL ) return NULL ; if ( root -> key == n1 root -> key == n2 ) return root ; Node * left_lca = findLCA ( root -> left , n1 , n2 ) ; Node * right_lca = findLCA ( root -> right , n1 , n2 ) ; if ( left_lca && right_lca ) return root ; return ( left_lca != NULL ) ? left_lca : right_lca ; } 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 -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; cout << " LCA ( 4 , ▁ 5 ) ▁ = ▁ " << findLCA ( root , 4 , 5 ) -> key ; cout << " nLCA ( 4 , ▁ 6 ) ▁ = ▁ " << findLCA ( root , 4 , 6 ) -> key ; cout << " nLCA ( 3 , ▁ 4 ) ▁ = ▁ " << findLCA ( root , 3 , 4 ) -> key ; cout << " nLCA ( 2 , ▁ 4 ) ▁ = ▁ " << findLCA ( root , 2 , 4 ) -> key ; return 0 ; }
Lowest Common Ancestor in a Binary Tree | Set 1 | C ++ program to find LCA of n1 and n2 using one traversal of Binary Tree . It handles all cases even when n1 or n2 is not there in Binary Tree ; A Binary Tree Node ; Utility function to create a new tree Node ; This function returns pointer to LCA of two given values n1 and n2 . v1 is set as true by this function if n1 is found v2 is set as true by this function if n2 is found ; Base case ; If either n1 or n2 matches with root 's key, report the presence  by setting v1 or v2 as true and return root (Note that if a key is ancestor of other, then the ancestor key becomes LCA) ; Look for keys in left and right subtrees ; If both of the above calls return Non - NULL , then one key is present in once subtree and other is present in other , So this node is the LCA ; Otherwise check if left subtree or right subtree is LCA ; Returns true if key k is present in tree rooted with root ; This function returns LCA of n1 and n2 only if both n1 and n2 are present in tree , otherwise returns NULL ; ; Initialize n1 and n2 as not visited ; Find lca of n1 and n2 using the technique discussed above ; Return LCA only if both n1 and n2 are present in tree ; Else return NULL ; Driver program to test above functions
#include <iostream> 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 ; } struct Node * findLCAUtil ( struct Node * root , int n1 , int n2 , bool & v1 , bool & v2 ) { if ( root == NULL ) return NULL ; if ( root -> key == n1 ) { v1 = true ; return root ; } if ( root -> key == n2 ) { v2 = true ; return root ; } Node * left_lca = findLCAUtil ( root -> left , n1 , n2 , v1 , v2 ) ; Node * right_lca = findLCAUtil ( root -> right , n1 , n2 , v1 , v2 ) ; if ( left_lca && right_lca ) return root ; return ( left_lca != NULL ) ? left_lca : right_lca ; } bool find ( Node * root , int k ) { if ( root == NULL ) return false ; if ( root -> key == k || find ( root -> left , k ) || find ( root -> right , k ) ) return true ; return false ; } Node * findLCA ( Node * root , int n1 , int n2 ) { bool v1 = false , v2 = false ; Node * lca = findLCAUtil ( root , n1 , n2 , v1 , v2 ) ; if ( v1 && v2 || v1 && find ( lca , n2 ) || v2 && find ( lca , n1 ) ) return lca ; return NULL ; } 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 -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; Node * lca = findLCA ( root , 4 , 5 ) ; if ( lca != NULL ) cout << " LCA ( 4 , ▁ 5 ) ▁ = ▁ " << lca -> key ; else cout << " Keys ▁ are ▁ not ▁ present ▁ " ; lca = findLCA ( root , 4 , 10 ) ; if ( lca != NULL ) cout << " nLCA ( 4 , ▁ 10 ) ▁ = ▁ " << lca -> key ; else cout << " nKeys ▁ are ▁ not ▁ present ▁ " ; return 0 ; }
Lowest Common Ancestor in a Binary Tree | Set 2 ( Using Parent Pointer ) | C ++ program to find lowest common ancestor using parent pointer ; A Tree Node ; A utility function to create a new BST node ; A utility function to insert a new node with given key in Binary Search Tree ; If the tree is empty , return a new node ; Otherwise , recur down the tree ; return the ( unchanged ) node pointer ; A utility function to find depth of a node ( distance of it from root ) ; To find LCA of nodes n1 and n2 in Binary Tree ; Find depths of two nodes and differences ; If n2 is deeper , swap n1 and n2 ; Move n1 up until it reaches the same level as n2 ; Now n1 and n2 are at same levels ; Driver method to test above functions
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { Node * left , * right , * parent ; int key ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> parent = 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 ) ; node -> left -> parent = node ; } else if ( key > node -> key ) { node -> right = insert ( node -> right , key ) ; node -> right -> parent = node ; } return node ; } int depth ( Node * node ) { int d = -1 ; while ( node ) { ++ d ; node = node -> parent ; } return d ; } Node * LCA ( Node * n1 , Node * n2 ) { int d1 = depth ( n1 ) , d2 = depth ( n2 ) ; int diff = d1 - d2 ; if ( diff < 0 ) { Node * temp = n1 ; n1 = n2 ; n2 = temp ; diff = - diff ; } while ( diff -- ) n1 = n1 -> parent ; while ( n1 && n2 ) { if ( n1 == n2 ) return n1 ; n1 = n1 -> parent ; n2 = n2 -> parent ; } return NULL ; } int main ( void ) { Node * root = NULL ; root = insert ( root , 20 ) ; root = insert ( root , 8 ) ; root = insert ( root , 22 ) ; root = insert ( root , 4 ) ; root = insert ( root , 12 ) ; root = insert ( root , 10 ) ; root = insert ( root , 14 ) ; Node * n1 = root -> left -> right -> left ; Node * n2 = root -> right ; Node * lca = LCA ( n1 , n2 ) ; printf ( " LCA ▁ of ▁ % d ▁ and ▁ % d ▁ is ▁ % d ▁ STRNEWLINE " , n1 -> key , n2 -> key , lca -> key ) ; return 0 ; }
Print common nodes on path from root ( or common ancestors ) | C ++ Program to find common nodes for given two nodes ; A Binary Tree Node ; Utility function to create a new tree Node ; Utility function to find the LCA of two given values n1 and n2 . ; Base case ; If either n1 or n2 matches with root 's key,  report the presence by returning root (Note  that if a key is ancestor of other, then the  ancestor key becomes LCA ; Look for keys in left and right subtrees ; If both of the above calls return Non - NULL , then one key is present in once subtree and other is present in other , So this node is the LCA ; Otherwise check if left subtree or right subtree is LCA ; Utility Function to print all ancestors of LCA ; base cases ; If target is present in either left or right subtree of this node , then print this node ; Else return false ; Function to find nodes common to given two nodes ; 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 ; } struct Node * findLCA ( struct Node * root , int n1 , int n2 ) { if ( root == NULL ) return NULL ; if ( root -> key == n1 root -> key == n2 ) return root ; Node * left_lca = findLCA ( root -> left , n1 , n2 ) ; Node * right_lca = findLCA ( root -> right , n1 , n2 ) ; if ( left_lca && right_lca ) return root ; return ( left_lca != NULL ) ? left_lca : right_lca ; } bool printAncestors ( struct Node * root , int target ) { if ( root == NULL ) return false ; if ( root -> key == target ) { cout << root -> key << " ▁ " ; return true ; } if ( printAncestors ( root -> left , target ) || printAncestors ( root -> right , target ) ) { cout << root -> key << " ▁ " ; return true ; } return false ; } bool findCommonNodes ( struct Node * root , int first , int second ) { struct Node * LCA = findLCA ( root , first , second ) ; if ( LCA == NULL ) return false ; printAncestors ( root , LCA -> key ) ; } 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 -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 8 ) ; root -> right -> left -> left = newNode ( 9 ) ; root -> right -> left -> right = newNode ( 10 ) ; if ( findCommonNodes ( root , 9 , 7 ) == false ) cout << " No ▁ Common ▁ nodes " ; return 0 ; }
Print Postorder traversal from given Inorder and Preorder traversals | C ++ program to print Postorder traversal from given Inorder and Preorder traversals . ; Find index of next item in preorder traversal in inorder . ; traverse left tree ; traverse right tree ; print root node at the end of traversal ; Driver code
#include <iostream> NEW_LINE using namespace std ; int preIndex = 0 ; int search ( int arr [ ] , int startIn , int endIn , int data ) { int i = 0 ; for ( i = startIn ; i < endIn ; i ++ ) { if ( arr [ i ] == data ) { return i ; } } return i ; } void printPost ( int arr [ ] , int pre [ ] , int inStrt , int inEnd ) { if ( inStrt > inEnd ) { return ; } int inIndex = search ( arr , inStrt , inEnd , pre [ preIndex ++ ] ) ; printPost ( arr , pre , inStrt , inIndex - 1 ) ; printPost ( arr , pre , inIndex + 1 , inEnd ) ; cout << arr [ inIndex ] << " ▁ " ; } int main ( ) { int arr [ ] = { 4 , 2 , 5 , 1 , 3 , 6 } ; int pre [ ] = { 1 , 2 , 4 , 5 , 3 , 6 } ; int len = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printPost ( arr , pre , 0 , len - 1 ) ; }
Binary Tree | Set 1 ( Introduction ) |
struct node { int data ; struct node * left ; struct node * right ; } ;