Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Node{
- public:
- int data;
- Node *left,*right;
- Node(int key){
- data=key;
- left=right=NULL;
- }
- };
- void Insert(Node **root_ref,int key){
- if(*root_ref==NULL){
- *root_ref=new Node(key);
- return;
- }
- if((*root_ref)->data<key)
- Insert(&((*root_ref)->right),key);
- else
- if((*root_ref)->data>key)
- Insert(&((*root_ref)->left),key);
- }
- int MinimumValue(Node *root){
- if(root==NULL)
- return INT_MIN;
- Node *temp=root;
- while(temp->left!=NULL)
- temp=temp->left;
- return temp->data;
- }
- int main(){
- Node *root=NULL;
- Insert(&root,5);
- Insert(&root,7);
- Insert(&root,4);
- Insert(&root,8);
- Insert(&root,1);
- Insert(&root,3);
- cout<<"minimum value in tree is :"<<MinimumValue(root);
- }
Add Comment
Please, Sign In to add comment