Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. //#define MAXB 1000
  2.  
  3. #define MAXS 1000
  4. typedef int nodetypeb;
  5. #include "s_polje.h"
  6. typedef nodeb elementtypes;
  7. //#include "stacka.h"
  8. #include <iostream>
  9. #include <cstdlib>
  10. #include "s.h"
  11. using namespace std;
  12.  
  13.  
  14. void Process(btree &B,nodeb n) {
  15. std::cout << LabelB(B,n) << " ";
  16. }
  17.  
  18. void Preorder(btree &B) {
  19.  
  20. stack S;
  21. InitS(S);
  22. PushS(S,RootB(B));
  23. do {
  24. nodeb n = TopS(S);
  25. PopS(S);
  26. Process(B,n);
  27. if (RightChildB(B,n) != -1)
  28. PushS(S,RightChildB(B,n));
  29. if (LeftChildB(B,n) != -1)
  30. PushS(S,LeftChildB(B,n));
  31. } while (!IsEmptyS(S));
  32. }
  33.  
  34.  
  35.  
  36.  
  37. void PrO(btree &B, nodeb n) {
  38. Process(B,n);
  39. if (LeftChildB(B,n) != lambdab)
  40. PrO(B,LeftChildB(B,n));
  41. if (RightChildB(B,n) != lambdab)
  42. PrO(B,RightChildB(B,n));
  43. }
  44.  
  45.  
  46.  
  47. void IO(btree &B, nodeb n) {
  48. if (LeftChildB(B,n) != lambdab)
  49. IO(B,LeftChildB(B,n));
  50. Process(B,n);
  51. if (RightChildB(B,n) != lambdab)
  52. IO(B,RightChildB(B,n));
  53. }
  54.  
  55. void Inorder(btree &B) {
  56. IO(B,RootB(B));
  57. }
  58.  
  59. void PoO(btree &B, nodeb n) {
  60. if (LeftChildB(B,n) != lambdab)
  61. PoO(B,LeftChildB(B,n));
  62. if (RightChildB(B,n) != lambdab)
  63. PoO(B,RightChildB(B,n));
  64. Process(B,n);
  65. }
  66.  
  67. void Postorder(btree &B) {
  68. PoO(B,RootB(B));
  69. }
  70.  
  71. int main(){
  72.  
  73. btree B;
  74. InitB(B,4);
  75. nodeb n = RootB(B);
  76.  
  77.  
  78. int izbor, ulaz;
  79. do{
  80.  
  81. cout << "1. Dodavanje korijena" << endl;
  82. cout << "2. Pomak lijevo" << endl;
  83. cout << "3. Pomak desno" << endl;
  84. cout << "4. Kreiraj lijevo" << endl;
  85. cout << "5. Kreiraj desno" << endl;
  86. cout << "6. Reset na korijen" << endl;
  87. cout << "9. Zavrsetak stabla" << endl;
  88. cout << "Izbor: "; cin >> izbor;
  89. switch(izbor){
  90. case 1: cin >> ulaz; CreateRootB(B, ulaz); n = RootB(B); cout << "Korijen kreiran" << endl; break;
  91. case 2: n = LeftChildB(B, n); cout << "Pomaknuto lijevo" << endl; break;
  92. case 3: n = RightChildB(B, n); cout << "Pomaknuto desno" << endl; break;
  93. case 4: cin >> ulaz; CreateLeftChildB(B, n, ulaz); cout << "Kreirano lijevo dijete" << endl; break;
  94. case 5: cin >> ulaz; CreateRightChildB(B, n, ulaz); cout << "Kreirano desno dijete" << endl; break;
  95. case 6: n = RootB(B); cout << "Resetirano" << endl; break;
  96. case 7: Preorder(B);
  97. case 9: break;
  98. }
  99. }while(izbor!=9);
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement