Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- ifstream f("arbore.in");
- int S[20], D[20], n, r;
- void RSD(int nod)
- {
- if(nod)
- {
- cout<<nod<<" ";
- RSD(S[nod]);
- RSD(D[nod]);
- }
- }
- void SRD(int nod)
- {
- if(nod)
- {
- SRD(S[nod]);
- cout<<nod<<" ";
- SRD(D[nod]);
- }
- }
- void SDR(int nod)
- {
- if(nod)
- {
- SDR(S[nod]);
- SDR(D[nod]);
- cout<<nod<<" ";
- }
- }
- int main()
- {
- int i,j, OK;
- f>>n;
- for(i=1; i<=n; ++i)
- f>>S[i];
- for(j=1; j<=n; ++j)
- f>>D[j];
- ///caut radacina
- for(i=1; i<=n; i++)
- {
- OK=0;
- ///presupun ca i 'apartine taiat' S[], i 'apartine taiat' D[] <=> i este radacina
- for(j=1; j<=n; j++)
- if(S[j]==i||D[j]==i)
- OK=1;
- if(!OK)
- r=i;
- }
- cout<<"RSD:";
- RSD(r);
- cout<<"\nSRD:";
- SRD(r);
- cout<<"\nSDR:";
- SDR(r);
- }
- /*
- abore.in
- 7
- 0 3 5 1 0 0 0
- 0 4 7 0 0 0 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement