codeparrot/xlcost-text-to-code huggingface dataset:
An interesting method to print reverse of a linked list | C program to print reverse of list ; Link list node ; Function to reverse the linked list ; For each node , print proper number of spaces before printing it ; use of carriage return to move back and print . ; Function to push a node ; Function to print linked list and find its length ; i for finding length of list ; Driver program to test above function ; Start with the empty list ; list nodes are as 6 5 4 3 2 1 ; printlist print the list and return the size of list ; print reverse list with help of carriage return function
#include <stdio.h> NEW_LINE #include <stdlib.h> NEW_LINE struct Node { int data ; struct Node * next ; } ; void printReverse ( struct Node * * head_ref , int n ) { int j = 0 ; struct Node * current = * head_ref ; while ( current != NULL ) { for ( int i = 0 ; i < 2 * ( n - j ) ; i ++ ) printf ( " ▁ " ) ; printf ( " % d \r " , current -> data ) ; current = current -> next ; j ++ ; } } void push ( struct Node * * head_ref , int new_data ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int printList ( struct Node * head ) { int i = 0 ; struct Node * temp = head ; while ( temp != NULL ) { printf ( " % d ▁ " , temp -> data ) ; temp = temp -> next ; i ++ ; } return i ; } int main ( ) { struct Node * head = NULL ; push ( & head , 1 ) ; push ( & head , 2 ) ; push ( & head , 3 ) ; push ( & head , 4 ) ; push ( & head , 5 ) ; push ( & head , 6 ) ; printf ( " Given ▁ linked ▁ list : STRNEWLINE " ) ; int n = printList ( head ) ; printf ( " Reversed Linked list : " printReverse ( & head , n ) ; printf ( " STRNEWLINE " ) ; return 0 ; }
Practice questions for Linked List and Recursion |
struct Node { int data ; struct Node * next ; } ;
Practice questions for Linked List and Recursion |
void fun1 ( struct Node * head ) { if ( head == NULL ) return ; fun1 ( head -> next ) ; cout << head -> data << " ▁ " ; }
Practice questions for Linked List and Recursion |
void fun2 ( struct Node * head ) { if ( head == NULL ) return ; cout << head -> data << " ▁ " ; if ( head -> next != NULL ) fun2 ( head -> next -> next ) ; cout << head -> data << " ▁ " ; }
Practice questions for Linked List and Recursion |  ; A linked list node ; Prints a linked list in reverse manner ; prints alternate nodes of a Linked List , first from head to end , and then from end to head . ; Given a reference ( pointer to pointer ) to the head of a list and an int , push a new node on the front of the list . ; allocate node ; put in the data ; link the old list off the new node ; move the head to point to the new node ; Driver code ; Start with the empty list ; Using push ( ) to construct below list 1 -> 2 -> 3 -> 4 -> 5
#include <bits/stdc++.h> NEW_LINE using namespace std ; class Node { public : int data ; Node * next ; } ; void fun1 ( Node * head ) { if ( head == NULL ) return ; fun1 ( head -> next ) ; cout << head -> data << " ▁ " ; } void fun2 ( Node * start ) { if ( start == NULL ) return ; cout << start -> data << " ▁ " ; if ( start -> next != NULL ) fun2 ( start -> next -> next ) ; cout << start -> data << " ▁ " ; } void push ( Node * * head_ref , int new_data ) { Node * new_node = new Node ( ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { Node * head = NULL ; push ( & head , 5 ) ; push ( & head , 4 ) ; push ( & head , 3 ) ; push ( & head , 2 ) ; push ( & head , 1 ) ; cout << " Output ▁ of ▁ fun1 ( ) ▁ for ▁ list ▁ 1 - > 2 - > 3 - > 4 - > 5 ▁ STRNEWLINE " ; fun1 ( head ) ; cout << " Output of fun2 ( ) for list 1 -> 2 -> 3 -> 4 -> 5 " ; fun2 ( head ) ; return 0 ; }
Density of Binary Tree in One Traversal | C ++ program to find density of a binary tree ; A binary tree node ; Helper function to allocates a new node ; Function to compute height and size of a binary tree ; compute height of each subtree ; increase size by 1 ; return larger of the two ; function to calculate density of a binary tree ; To store size ; Finds height and size ; Driver code to test above methods
#include <bits/stdc++.h> NEW_LINE struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } int heighAndSize ( Node * node , int & size ) { if ( node == NULL ) return 0 ; int l = heighAndSize ( node -> left , size ) ; int r = heighAndSize ( node -> right , size ) ; size ++ ; return ( l > r ) ? l + 1 : r + 1 ; } float density ( Node * root ) { if ( root == NULL ) return 0 ; int size = 0 ; int _height = heighAndSize ( root , size ) ; return ( float ) size / _height ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; printf ( " Density ▁ of ▁ given ▁ binary ▁ tree ▁ is ▁ % f " , density ( root ) ) ; return 0 ; }
Given only a pointer / reference to a node to be deleted in a singly linked list , how do you delete it ? |
void deleteNode ( Node * node ) { * node = * ( node -> next ) ; }
Squareroot ( n ) | C ++ program to find sqrt ( n ) 'th node  of a linked list  ; Linked list node ; Function to get the sqrt ( n ) th node of a linked list ; Traverse the list ; check if j = sqrt ( i ) ; for first node ; increment j if j = sqrt ( i ) ; return node 's data  ; function to add a new node at the beginning of the list ; allocate node ; put in the data ; link the old list off the new node ; move the head to point to the new node ; Driver program to test above function ; Start with the empty list
#include <bits/stdc++.h> NEW_LINE using namespace std ; class Node { public : int data ; Node * next ; } ; int printsqrtn ( Node * head ) { Node * sqrtn = NULL ; int i = 1 , j = 1 ; while ( head != NULL ) { if ( i == j * j ) { if ( sqrtn == NULL ) sqrtn = head ; else sqrtn = sqrtn -> next ; j ++ ; } i ++ ; head = head -> next ; } return sqrtn -> data ; } void print ( Node * head ) { while ( head != NULL ) { cout << head -> data << " ▁ " ; head = head -> next ; } cout << endl ; } void push ( Node * * head_ref , int new_data ) { Node * new_node = new Node ( ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { Node * head = NULL ; push ( & head , 40 ) ; push ( & head , 30 ) ; push ( & head , 20 ) ; push ( & head , 10 ) ; cout << " Given ▁ linked ▁ list ▁ is : " ; print ( head ) ; cout << " sqrt ( n ) th ▁ node ▁ is ▁ " << printsqrtn ( head ) ; return 0 ; }
Find the fractional ( or n / k | C ++ program to find fractional node in a linked list ; Linked list node ; Function to create a new node with given data ; Function to find fractional node in the linked list ; Corner cases ; Traverse the given list ; For every k nodes , we move fractionalNode one step ahead . ; First time we see a multiple of k ; A utility function to print a linked list ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE struct Node { int data ; Node * next ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> next = NULL ; return new_node ; } Node * fractionalNodes ( Node * head , int k ) { if ( k <= 0 head == NULL ) return NULL ; Node * fractionalNode = NULL ; int i = 0 ; for ( Node * temp = head ; temp != NULL ; temp = temp -> next ) { if ( i % k == 0 ) { if ( fractionalNode == NULL ) fractionalNode = head ; else fractionalNode = fractionalNode -> next ; } i ++ ; } return fractionalNode ; } void printList ( Node * node ) { while ( node != NULL ) { printf ( " % d ▁ " , node -> data ) ; node = node -> next ; } printf ( " STRNEWLINE " ) ; } int main ( void ) { Node * head = newNode ( 1 ) ; head -> next = newNode ( 2 ) ; head -> next -> next = newNode ( 3 ) ; head -> next -> next -> next = newNode ( 4 ) ; head -> next -> next -> next -> next = newNode ( 5 ) ; int k = 2 ; printf ( " List ▁ is ▁ " ) ; printList ( head ) ; Node * answer = fractionalNodes ( head , k ) ; printf ( " Fractional node is " printf ( " % d STRNEWLINE " , answer -> data ) ; return 0 ; }
Find modular node in a linked list | C ++ program to find modular node in a linked list ; Linked list node ; Function to create a new node with given data ; Function to find modular node in the linked list ; Corner cases ; Traverse the given list ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE struct Node { int data ; Node * next ; } ; Node * newNode ( int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> next = NULL ; return new_node ; } Node * modularNode ( Node * head , int k ) { if ( k <= 0 head == NULL ) return NULL ; int i = 1 ; Node * modularNode = NULL ; for ( Node * temp = head ; temp != NULL ; temp = temp -> next ) { if ( i % k == 0 ) modularNode = temp ; i ++ ; } return modularNode ; } int main ( void ) { Node * head = newNode ( 1 ) ; head -> next = newNode ( 2 ) ; head -> next -> next = newNode ( 3 ) ; head -> next -> next -> next = newNode ( 4 ) ; head -> next -> next -> next -> next = newNode ( 5 ) ; int k = 2 ; Node * answer = modularNode ( head , k ) ; printf ( " Modular node is " if ( answer != NULL ) printf ( " % d STRNEWLINE " , answer -> data ) ; else printf ( " null STRNEWLINE " ) ; return 0 ; }
Modify contents of Linked List | C ++ implementation to modify the contents of the linked list ; Linked list node ; Function to insert a node at the beginning of the linked list ; allocate node ; put in the data ; link the old list at the end of the new node ; move the head to point to the new node ; function to print the linked list ; Function to middle node of list . ; Advance ' fast ' two nodes , and advance ' slow ' one node ; If number of nodes are odd then update slow by slow -> next ; ; function to modify the contents of the linked list . ; Create Stack . ; Traverse the list by using temp until stack is empty . ; Driver program to test above ; creating the linked list ; Call Function to Find the starting point of second half of list . ; Call function to modify the contents of the linked list . ; print the modified linked list
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printList ( struct Node * ) ; struct Node { int data ; struct Node * next ; } ; void push ( struct Node * * head_ref , int new_data ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> next = * head_ref ; * head_ref = new_node ; } void printList ( struct Node * head ) { if ( ! head ) return ; while ( head -> next != NULL ) { cout << head -> data << " ▁ - > ▁ " ; head = head -> next ; } cout << head -> data << endl ; } Node * find_mid ( Node * head ) { Node * temp = head , * slow = head , * fast = head ; while ( fast && fast -> next ) { slow = slow -> next ; fast = fast -> next -> next ; } if ( fast ) slow = slow -> next ; return slow ; } void modifyTheList ( struct Node * head , struct Node * slow ) { stack < int > s ; Node * temp = head ; while ( slow ) { s . push ( slow -> data ) ; slow = slow -> next ; } while ( ! s . empty ( ) ) { temp -> data = temp -> data - s . top ( ) ; temp = temp -> next ; s . pop ( ) ; } } int main ( ) { struct Node * head = NULL , * mid ; push ( & head , 10 ) ; push ( & head , 7 ) ; push ( & head , 12 ) ; push ( & head , 8 ) ; push ( & head , 9 ) ; push ( & head , 2 ) ; mid = find_mid ( head ) ; modifyTheList ( head , mid ) ; cout << " Modified ▁ List : " << endl ; printList ( head ) ; return 0 ; }
Binary Search Tree | Set 1 ( Search and Insertion ) | C function to search a given key in a given BST ; Base Cases : root is null or key is present at root ; Key is greater than root 's key ; Key is smaller than root 's key
struct node * search ( struct node * root , int key ) { if ( root == NULL root -> key == key ) return root ; if ( root -> key < key ) return search ( root -> right , key ) ; return search ( root -> left , key ) ; }
Modify a binary tree to get preorder traversal using right pointers only | C code to modify binary tree for traversal using only right pointer ; A binary tree node has data , left child and right child ; function that allocates a new node with the given data and NULL left and right pointers . ; Function to modify tree ; if the left tree exists ; get the right - most of the original left subtree ; set root right to left subtree ; if the right subtree does not exists we are done ! ; set right pointer of right - most of the original left subtree ; modify the rightsubtree ; printing using right pointer only ; Driver program to test above functions ; Constructed binary tree is 10 / \ 8 2 / \ 3 5
#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 struct Node ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } struct Node * modifytree ( struct Node * root ) { struct Node * right = root -> right ; struct Node * rightMost = root ; if ( root -> left ) { rightMost = modifytree ( root -> left ) ; root -> right = root -> left ; root -> left = NULL ; } if ( ! right ) return rightMost ; rightMost -> right = right ; rightMost = modifytree ( right ) ; return rightMost ; } void printpre ( struct Node * root ) { while ( root != NULL ) { cout << root -> data << " ▁ " ; root = root -> right ; } } int main ( ) { struct Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> right = newNode ( 2 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 5 ) ; modifytree ( root ) ; printpre ( root ) ; return 0 ; }
Construct BST from its given level order traversal | C ++ implementation to construct a BST from its level order traversal ; node of a BST ; function to get a new node ; Allocate memory ; put in the data ; function to construct a BST from its level order traversal ; function to print the inorder traversal ; Driver program to test above
#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 ; } Node * LevelOrder ( Node * root , int data ) { if ( root == NULL ) { root = getNode ( data ) ; return root ; } if ( data <= root -> data ) root -> left = LevelOrder ( root -> left , data ) ; else root -> right = LevelOrder ( root -> right , data ) ; return root ; } Node * constructBst ( int arr [ ] , int n ) { if ( n == 0 ) return NULL ; Node * root = NULL ; for ( int i = 0 ; i < n ; i ++ ) root = LevelOrder ( root , arr [ i ] ) ; return root ; } void inorderTraversal ( Node * root ) { if ( ! root ) return ; inorderTraversal ( root -> left ) ; cout << root -> data << " ▁ " ; inorderTraversal ( root -> right ) ; } int main ( ) { int arr [ ] = { 7 , 4 , 12 , 3 , 6 , 8 , 1 , 5 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; Node * root = constructBst ( arr , n ) ; cout << " Inorder ▁ Traversal : ▁ " ; inorderTraversal ( root ) ; return 0 ; }
Modify a binary tree to get preorder traversal using right pointers only | C ++ code to modify binary tree for traversal using only right pointer ; A binary tree node has data , left child and right child ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; An iterative process to set the right pointer of Binary tree ; Base Case ; Create an empty stack and push root to it ; Pop all items one by one . Do following for every popped item a ) print it b ) push its right child c ) push its left child Note that right child is pushed first so that left is processed first ; Pop the top item from stack ; Push right and left children of the popped node to stack ; check if some previous node exists ; set the right pointer of previous node to currrent ; set previous node as current node ; printing using right pointer only ; Driver code ; Constructed binary tree is 10 / \ 8 2 / \ 3 5
#include <iostream> NEW_LINE #include <stack> NEW_LINE #include <stdio.h> NEW_LINE #include <stdlib.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 struct Node ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } void modifytree ( struct Node * root ) { if ( root == NULL ) return ; stack < Node * > nodeStack ; nodeStack . push ( root ) ; struct Node * pre = NULL ; while ( nodeStack . empty ( ) == false ) { struct Node * node = nodeStack . top ( ) ; nodeStack . pop ( ) ; if ( node -> right ) nodeStack . push ( node -> right ) ; if ( node -> left ) nodeStack . push ( node -> left ) ; if ( pre != NULL ) { pre -> right = node ; } pre = node ; } } void printpre ( struct Node * root ) { while ( root != NULL ) { cout << root -> data << " ▁ " ; root = root -> right ; } } int main ( ) { struct Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> right = newNode ( 2 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 5 ) ; modifytree ( root ) ; printpre ( root ) ; return 0 ; }
Check given array of size n can represent BST of n levels or not | C ++ program to Check given array can represent BST or not ; structure for Binary Node ; To create a Tree with n levels . We always insert new node to left if it is less than previous value . ; Please refer below post for details of this function . www . geeksforgeeks . org / a - program - to - check - if - a - binary - tree - is - bst - or - not / https : ; Allow only distinct values ; Returns tree if given array of size n can represent a BST of n levels . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int key ; struct Node * right , * left ; } ; Node * newNode ( int num ) { Node * temp = new Node ; temp -> key = num ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } Node * createNLevelTree ( int arr [ ] , int n ) { Node * root = newNode ( arr [ 0 ] ) ; Node * temp = root ; for ( int i = 1 ; i < n ; i ++ ) { if ( temp -> key > arr [ i ] ) { temp -> left = newNode ( arr [ i ] ) ; temp = temp -> left ; } else { temp -> right = newNode ( arr [ i ] ) ; temp = temp -> right ; } } return root ; } bool isBST ( Node * root , int min , int max ) { if ( root == NULL ) return true ; if ( root -> key < min root -> key > max ) return false ; return ( isBST ( root -> left , min , ( root -> key ) - 1 ) && isBST ( root -> right , ( root -> key ) + 1 , max ) ) ; } bool canRepresentNLevelBST ( int arr [ ] , int n ) { Node * root = createNLevelTree ( arr , n ) ; return isBST ( root , INT_MIN , INT_MAX ) ; } int main ( ) { int arr [ ] = { 512 , 330 , 78 , 11 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( canRepresentNLevelBST ( arr , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Check given array of size n can represent BST of n levels or not | C ++ program to Check given array can represent BST or not ; Driver code ; This element can be inserted to the right of the previous element , only if it is greater than the previous element and in the range . ; max remains same , update min ; This element can be inserted to the left of the previous element , only if it is lesser than the previous element and in the range . ; min remains same , update max ; if the loop completed successfully without encountering else condition
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int arr [ ] = { 5123 , 3300 , 783 , 1111 , 890 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = INT_MAX ; int min = INT_MIN ; bool flag = true ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] && arr [ i ] > min && arr [ i ] < max ) { min = arr [ i - 1 ] ; } else if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] > min && arr [ i ] < max ) { max = arr [ i - 1 ] ; } else { flag = false ; break ; } } if ( flag ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Convert a normal BST to Balanced BST | C ++ program to convert a left unbalanced BST to a balanced BST ; A binary tree node has data , pointer to left child and a pointer to right child ; This function traverse the skewed binary tree and stores its nodes pointers in vector nodes [ ] ; Base case ; Store nodes in Inorder ( which is sorted order for BST ) ; Recursive function to construct binary tree ; base case ; Get the middle element and make it root ; Using index in Inorder traversal , construct left and right subtress ; This functions converts an unbalanced BST to a balanced BST ; Store nodes of given BST in sorted order ; Constucts BST from nodes [ ] ; Utility function to create a new node ; Function to do preorder traversal of tree ; Driver program ; Constructed skewed binary tree is 10 / 8 / 7 / 6 / 5
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; Node * left , * right ; } ; void storeBSTNodes ( Node * root , vector < Node * > & nodes ) { if ( root == NULL ) return ; storeBSTNodes ( root -> left , nodes ) ; nodes . push_back ( root ) ; storeBSTNodes ( root -> right , nodes ) ; } Node * buildTreeUtil ( vector < Node * > & nodes , int start , int end ) { if ( start > end ) return NULL ; int mid = ( start + end ) / 2 ; Node * root = nodes [ mid ] ; root -> left = buildTreeUtil ( nodes , start , mid - 1 ) ; root -> right = buildTreeUtil ( nodes , mid + 1 , end ) ; return root ; } Node * buildTree ( Node * root ) { vector < Node * > nodes ; storeBSTNodes ( root , nodes ) ; int n = nodes . size ( ) ; return buildTreeUtil ( nodes , 0 , n - 1 ) ; } Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } void preOrder ( Node * node ) { if ( node == NULL ) return ; printf ( " % d ▁ " , node -> data ) ; preOrder ( node -> left ) ; preOrder ( node -> right ) ; } int main ( ) { Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> left -> left = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 6 ) ; root -> left -> left -> left -> left = newNode ( 5 ) ; root = buildTree ( root ) ; printf ( " Preorder ▁ traversal ▁ of ▁ balanced ▁ " " BST ▁ is ▁ : ▁ STRNEWLINE " ) ; preOrder ( root ) ; return 0 ; }
Find the node with minimum value in a Binary Search Tree | C ++ program to find minimum value node in binary search Tree . ; 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 . ; Give a binary search tree and a number , inserts a new node with the given number in the correct place in the tree . Returns the new root pointer which the caller should then use ( the standard trick to avoid using reference parameters ) . ; 1. If the tree is empty , return a new , single node ; 2. Otherwise , recur down the tree ; return the ( unchanged ) node pointer ; Given a non - empty binary search tree , return the minimum data value found in that tree . Note that the entire tree does not need to be searched . ; loop down to find the leftmost leaf ; 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 * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } struct node * insert ( struct node * node , int data ) { if ( node == NULL ) return ( newNode ( data ) ) ; else { if ( data <= node -> data ) node -> left = insert ( node -> left , data ) ; else node -> right = insert ( node -> right , data ) ; return node ; } } int minValue ( struct node * node ) { struct node * current = node ; while ( current -> left != NULL ) { current = current -> left ; } return ( current -> data ) ; } int main ( ) { struct node * root = NULL ; root = insert ( root , 4 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 6 ) ; insert ( root , 5 ) ; cout << " Minimum value in BST is " getchar ( ) ; return 0 ; }