Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream.h>
- ifstream f("arbore.in");
- #include<iostream.h>
- typedef struct nod
- {
- int inf;
- nod *st,*dr;
- }ARB;
- void SRD(ARB *r)
- {
- if(r)
- {
- SRD(r->st);
- cout<<r->inf<<" ";
- SRD(r->dr);
- }
- }
- void DRS(ARB *r)
- {
- if(r)
- {
- DRS(r->dr);
- cout<<r->inf<<" ";
- DRS(r->st);
- }
- }
- void inserare(ARB*&r,int x)
- {
- if(r)
- {
- if(x<r->inf)
- inserare(r->st,x);
- else
- inserare(r->dr,x);
- }
- else
- {
- r=new ARB;
- r->inf=x;
- r->st=NULL;
- r->dr=NULL;
- }
- }
- int main()
- {
- int n,x,i;
- ARB *rad;
- rad=NULL;
- f>>n;
- for(i=1;i<=n;i++)
- {
- f>>x;
- inserare(rad,x);
- }
- //ordonare crescatoare
- cout<<"Ordonare crescatoare: ";
- SRD(rad);
- cout<<endl;
- //ordonare descrescatoare
- cout<<"Ordonare descrescatoare: ";
- DRS(rad);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment