Advertisement
a53

Inordine1

a53
Dec 28th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. ifstream fin("inordine1.in");
  6. ofstream fout("inordine1.out");
  7.  
  8. struct nod{
  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 inordine(nod * p)
  29. {
  30. if(p != NULL)
  31. {
  32. inordine(p -> st);
  33. fout << p -> info <<' ';
  34. inordine(p -> dr);
  35. }
  36. }
  37.  
  38. void stergeTot(nod * & p)
  39. {
  40. if(p != NULL)
  41. {
  42. stergeTot(p -> st);
  43. stergeTot(p -> dr);
  44. delete p;
  45. p = NULL;
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. nod * p = NULL;
  52. citire(p);
  53. if(p -> st)
  54. inordine(p -> st);
  55. fout << p -> info <<' ';
  56. if(p -> dr)
  57. inordine(p -> dr);
  58.  
  59. stergeTot(p);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement