Advertisement
a53

BiArbore

a53
Dec 28th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. ifstream fin("biarbore.in");
  6. ofstream fout("biarbore.out");
  7. struct nod
  8. {
  9. int info;
  10. nod * st, *dr;
  11. };
  12.  
  13. void citire(nod * & p)
  14. {
  15. int x;
  16. fin>>x;
  17. if(x==0)
  18. p=NULL;
  19. else
  20. {
  21. p=new nod;
  22. p->info=x;
  23. citire(p->st);
  24. citire(p->dr);
  25. }
  26. }
  27.  
  28. void stergeTot(nod * & p)
  29. {
  30. if(p!=NULL)
  31. {
  32. stergeTot(p->st);
  33. stergeTot(p->dr);
  34. delete p;
  35. p=NULL;
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. nod * p=NULL;
  42. citire(p);
  43. int info_st,info_dr;
  44. if(!p->st)
  45. info_st=0;
  46. else
  47. info_st=p->st->info;
  48. if(!p->dr)
  49. info_dr=0;
  50. else
  51. info_dr=p->dr->info;
  52. if(p->st||p->dr)
  53. fout<<info_st<<' '<<info_dr;
  54. else
  55. fout<<0;
  56. stergeTot(p);
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement