Advertisement
a53

Postordine

a53
Dec 28th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. ifstream cin("postordine.in");
  5. ofstream cout("postordine.out");
  6. int n,rad,i,s[1001],d[1001],v[1001],t[1001];
  7.  
  8. void SDR(int k)
  9. {
  10. if(s[k]) SDR(s[k]);
  11. if(d[k]) SDR(d[k]);
  12. cout<<v[k]<<' ';
  13. }
  14.  
  15. int main()
  16. {
  17. cin>>n;
  18. for(i=1;i<=n;i++)
  19. {
  20. cin>>v[i]>>s[i]>>d[i];
  21. if(s[i])
  22. t[s[i]]=i;
  23. if(d[i])
  24. t[d[i]]=i;
  25. }
  26. for(i=1;i<=n;i++)
  27. if(t[i]==0)
  28. {
  29. rad=i;
  30. break;
  31. }
  32. SDR(rad);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement