Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream f("date.in");
  5. struct NOD
  6. {
  7. int inf;
  8. NOD *st,*dr;
  9. };
  10. NOD *creare()
  11. {
  12. int x;
  13. cout<<"x= ";
  14. f>>x;
  15. if(x==0)
  16. return NULL;
  17. else
  18. {
  19. NOD *nou;
  20. nou=new NOD;
  21. nou->inf=x;
  22. nou->st=creare();
  23. nou->dr=creare();
  24. return nou;
  25. }
  26. }
  27. void RSD(NOD *p)
  28. {
  29. if(p!=NULL)
  30. {
  31. cout<<p->inf<<" ";
  32. RSD(p->st);
  33. RSD(p->dr);
  34. }
  35. }
  36. void SRD(NOD *p)
  37. {
  38. if(p!=NULL)
  39. {
  40. SRD(p->st);
  41. cout<<p->inf<<" ";
  42. SRD(p->dr);
  43. }
  44. }
  45. void SDR(NOD *p)
  46. {
  47. if(p!=NULL)
  48. {
  49. RSD(p->st);
  50. RSD(p->dr);
  51. cout<<p->inf<<" ";
  52. }
  53. }
  54. int main()
  55. {
  56. NOD *r=creare();
  57. cout<<" \nparcurgere RSD ";
  58. RSD(r);
  59. cout<<"\n";
  60. cout<<"parcurgere SRD ";
  61. SRD(r);
  62. cout<<"\n";
  63. cout<<"parcurgere SDR ";
  64. SDR(r);
  65. cout<<"\n";
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement