Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct nod
- { int info;
- nod *s,*d;
- };
- nod *r;
- void creeare(nod *&r,int n)
- { if(r!=NULL)
- if(n<r->info)
- creeare(r->s,n);
- else
- if(n>r->info)
- creeare(r->d,n);
- else
- cout<<"valoarea citita exista in arbore"<<endl;
- else
- { r=new nod;
- r->info=n;
- r->s=NULL;
- r->d=NULL;
- }
- }
- void rsd(nod *r)
- { if(r!=NULL)
- { cout<<r->info<<" ";
- rsd(r->s);
- rsd(r->d);
- }
- }
- int max(nod *r)
- { if(r==NULL)
- return 0;
- if(r->d!=NULL)
- return max(r->d);
- else
- return r->info;
- }
- int min(nod *r)
- { if(r==NULL)
- return 0;
- if(r->s!=NULL)
- return min(r->s);
- else
- return r->info;}
- int cautare(nod *r,int x)
- { if(r==NULL)
- return 0;
- else
- if(r->info==x)
- return 1;
- else
- if(x<r->info)
- return cautare(r->s,x);
- else
- return cautare(r->d,x);
- }
- void inserare(nod *&r,int x)
- { if(r!=NULL)
- if(r->info==x)
- cout<<"eticheta exista"<<endl;
- else
- if(r->info>x)
- inserare(r->s,x);
- else
- inserare(r->d,x);
- else
- { r=new nod;
- r->info=x;
- r->s=NULL;
- r->d=NULL;
- }
- }
- int main ()
- { int n,x;
- r=NULL;
- cin>>n;
- while(n!=0)
- { creeare(r,n);
- cin>>n;}
- cin>>x;
- rsd(r);
- cout<<endl;
- cout<<"nodul maxim este "<<max(r)<<endl;
- cout<<"nodul minim este "<<min(r)<<endl;
- if(cautare(r,x))
- cout<<"valoarea exista"<<endl;
- else
- cout<<"valoarea nu exista"<<endl;
- inserare(r,x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement