Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. //#define MAXB 1000
  2. #define MAXS 1000
  3. typedef int nodetypeb;
  4. #include "btree.h"
  5. typedef nodeb elementtypes;
  6. #include "stack.h"
  7. #include <iostream>
  8. #include <cstdlib>
  9.  
  10. using namespace std;
  11.  
  12. void Process(btree &B,nodeb n) {
  13. std::cout << LabelB(B,n) << " ";
  14. }
  15.  
  16.  
  17. void PoO(btree &B, nodeb n) {
  18. if (LeftChildB(B,n) != lambdab)
  19. PoO(B,LeftChildB(B,n));
  20. if (RightChildB(B,n) != lambdab)
  21. PoO(B,RightChildB(B,n));
  22. Process(B,n);
  23. }
  24.  
  25. void Postorder(btree &B) {
  26. PoO(B,RootB(B));
  27. }
  28.  
  29.  
  30.  
  31. void postOrder(btree &B)
  32. {
  33. stack S;
  34. InitS(S);
  35. bool T
  36. nodeb n = RootB(B);
  37. if (RootB(B) == NULL)
  38. return;
  39.  
  40. do
  41. {
  42.  
  43. while ()
  44. {
  45.  
  46. if (RightChildB(B,n))
  47. PushS(S, RightChildB(B,n));
  48. PushS(S, RootB(B));
  49. n = RightChildB(B,n);
  50. T = true;
  51. }
  52. }
  53. n = PopS(S);
  54. if (RightChildB(B,n) && TopS(S) == RightChildB(B,n))
  55. {
  56. PopS(S);
  57. PushS(S, n);
  58. n = RightChildB(B,n);
  59.  
  60. }
  61. else
  62. {
  63.  
  64. std::cout << " " << LabelB(B,n) << std::endl;
  65. n = NULL;
  66. }
  67. } while (!IsEmptyS(S));
  68. }
  69.  
  70. int main () {
  71. btree B;
  72. int br;
  73. int m;
  74. char izbor;
  75. int broj;
  76. cout << "broj cvorova: ";
  77. cin >> br;
  78. int i = 0;
  79. cout << "Root: ";
  80. cin >> m;
  81. InitB(B,m);
  82. nodeb n = RootB(B);
  83. while(i<br){
  84. cout << "Lijevo(L) Desno(D) Gore(U)" << endl;
  85. cin >> izbor;
  86. if(izbor == 'L'){
  87. cin >> broj;
  88. CreateLeftChildB(B,n,broj);
  89. n = LeftChildB(B,n);
  90. i++;}
  91. if(izbor == 'D'){
  92. cin >> broj;
  93. CreateRightChildB(B,n,broj);
  94. n = RightChildB(B,n);
  95. i++;}
  96. if(izbor == 'U'){
  97. n = ParentB(B,n);}
  98. }
  99. postOrder(B);
  100. std::cout << std::endl;
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement