Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- ifstream f("e:\\info\\arborebinar.txt");
- struct nod
- { int info;
- nod *s,*d;
- };
- nod *r;
- void creare(nod *&r)
- { int n;
- f>>n;
- if (n==0)
- r=NULL;
- else
- { r=new nod;
- r->info=n;
- creare(r->s);
- creare(r->d);
- }
- }
- void rsd(nod *r)//preordine parcurgere radacina stanga dreapta
- { if(r!=NULL)
- { cout<<r->info<<" ";
- rsd(r->s);
- rsd(r->d);
- }
- }
- void srd(nod *r) //inordine parcurgere stanga radacina dreapta
- { if(r!=NULL)
- { srd(r->s);
- cout<<r->info<<" ";
- srd(r->d);
- }
- }
- void sdr(nod *r) //post ordine parcurgere stanga dreapta radacina
- { if(r!=NULL)
- { sdr(r->s);
- sdr(r->d);
- cout<<r->info<<" ";
- }
- }
- int main()
- { creare(r);
- cout<<"rsd=";
- rsd(r);
- cout<<endl;
- cout<<"srd=";
- srd(r);
- cout<<endl;
- cout<<"sdr=";
- sdr(r);
- }
- f:1 2 4 0 7 8 0 0 0 0 3 5 9 0 0 10 0 0 6 0 11 0 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement