Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("date.in");
- struct NOD
- {
- int inf;
- NOD *st,*dr;
- };
- NOD *creare()
- {
- int x;
- cout<<"x= ";
- f>>x;
- if(x==0)
- return NULL;
- else
- {
- NOD *nou;
- nou=new NOD;
- nou->inf=x;
- nou->st=creare();
- nou->dr=creare();
- return nou;
- }
- }
- void RSD(NOD *p)
- {
- if(p!=NULL)
- {
- cout<<p->inf<<" ";
- RSD(p->st);
- RSD(p->dr);
- }
- }
- void SRD(NOD *p)
- {
- if(p!=NULL)
- {
- SRD(p->st);
- cout<<p->inf<<" ";
- SRD(p->dr);
- }
- }
- void SDR(NOD *p)
- {
- if(p!=NULL)
- {
- RSD(p->st);
- RSD(p->dr);
- cout<<p->inf<<" ";
- }
- }
- int main()
- {
- NOD *r=creare();
- cout<<" \nparcurgere RSD ";
- RSD(r);
- cout<<"\n";
- cout<<"parcurgere SRD ";
- SRD(r);
- cout<<"\n";
- cout<<"parcurgere SDR ";
- SDR(r);
- cout<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement