Advertisement
a53

Inaltime1

a53
Dec 30th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream cin("inaltime1.in");
  4. ofstream cout("inaltime1.out");
  5. struct nod
  6. {int nr;
  7. nod* st,*dr;
  8. };
  9. nod *c;
  10. int n,s[101],i,sf;
  11. nod *r[101];
  12.  
  13. nod *arb()
  14. {//int n;
  15. nod *c;
  16. cin>>n;
  17. if(n)
  18. {
  19. c=new nod;
  20. c->nr=n;
  21. c->st=arb();
  22. c->dr=arb();
  23. return c;
  24. }
  25. else return 0;
  26. }
  27.  
  28. int h(nod *r)
  29. {
  30. if (r==0) return 0;
  31. else return 1+max(h(r->st),h(r->dr));
  32. }
  33. /*
  34. int h1(nod *r)
  35. {if(r==0) return 0;
  36. else return 1+h1(r->st);
  37. }
  38.  
  39. int h2(nod *r)
  40. {if(r==0) return 0;
  41. else return 1+h2(r->dr);
  42. }
  43. */
  44. int main()
  45. {
  46. c=arb();
  47. cout<<h(c)<<'\n';
  48. //cout<<h1(c)<<endl;
  49. //cout<<h2(c)<<endl;
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement