Advertisement
a53

BiMax

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