Posts

Showing posts from May 1, 2018

Data Structure LAb 10

Source Code: #include <iostream> using namespace std; struct tree { int num; tree*left=NULL; tree*right=NULL; };tree*root=NULL; tree*nodeptr=NULL; //add tree void add(int n) { tree* t=new tree; t->num=n; t->left=NULL; t->right=NULL; bool flag=false; if(root==NULL) { root=t; flag=true; } else { nodeptr=root; while(nodeptr!=NULL) { if(n<nodeptr->num) { if(nodeptr->left!=NULL) { nodeptr=nodeptr->left; } else { nodeptr->left=t; flag=true; break; } } else if(n>nodeptr->num) { if(nodeptr->right!=NULL) { nodeptr=nodeptr->right; } else { flag=true; nodeptr->right=t; break; } } else { cout<<"Duplicate NUmber \n"; break; } } } if(flag==true) cout<<"Va...