Guest User

Untitled

a guest
Jul 19th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. #include <iostream>
  2. //#include "ostablo.h"
  3. //#include "bstablo_polje.h"
  4. #include "bstablo_pokazivac.h"
  5. using namespace std;
  6.  
  7. void opcenito_stablo()
  8. {/*
  9. tr T;
  10.  
  11. InitT(9, T);
  12. T.el[0].vrij = 'F';
  13. T.el[0].c = -1;
  14. T.el[0].b = 6;
  15.  
  16. T.el[1].vrij = 'E';
  17. T.el[1].c = -1;
  18. T.el[1].b = -1;
  19.  
  20. T.el[2].vrij = 'D';
  21. T.el[2].c = 0;
  22. T.el[2].b = -1;
  23.  
  24. T.el[3].vrij = 'H';
  25. T.el[3].c = -1;
  26. T.el[3].b = -1;
  27.  
  28. T.el[4].vrij = 'B';
  29. T.el[4].c = 2;
  30. T.el[4].b = 10;
  31.  
  32. T.el[6].vrij = 'G';
  33. T.el[6].c = -1;
  34. T.el[6].b = 3;
  35.  
  36. T.el[9].vrij = 'A';
  37. T.el[9].c = 4;
  38. T.el[9].b = -1;
  39.  
  40. T.el[10].vrij = 'C';
  41. T.el[10].c = 1;
  42. T.el[10].b = -1;
  43.  
  44. cout << "FirstChildT(2, T): " << FirstChildT(2, T) << endl;
  45. cout << "FirstChildT(6, T): " << FirstChildT(6, T) << endl;
  46. cout << "NextSiblingT(6, T): " << NextSiblingT(6, T) << endl;
  47. cout << "NextSiblingT(1, T): " << NextSiblingT(1, T) << endl;
  48. cout << "ParentT(6, T): " << ParentT(6, T) << endl;
  49. cout << "ParentT(9, T): " << ParentT(9, T) << endl;
  50. cout << "LabelT(6, T): " << LabelT(6, T) << endl;
  51. cout << "ChangeLabelT('L', 6, T)" << endl;
  52. ChangeLabelT('L', 6, T);
  53. cout << "LabelT(6, T): " << LabelT(6, T) << endl;
  54. cout << "RootT(T): " << RootT(T) << endl;
  55. cout << "CreateT('Z', 10, T): " << endl;
  56. CreateT('Z', 10, T);
  57. cout << "NextSiblingT(1, T): " << NextSiblingT(1, T) << endl;
  58. cout << "DeleteT(4, T): " << endl;
  59. DeleteT(4, T);
  60. cout << "FirstChildT(RootT(T), T): " << FirstChildT(RootT(T), T) << endl;*/
  61. }
  62.  
  63. void binarno_stablo_polje()
  64. {/*
  65. bt T;
  66.  
  67. InitB(1, T);
  68. cout << CreateLeftB(2, 1, T) << endl;
  69. cout << CreateRightB(3, 1, T) << endl;
  70. cout << CreateRightB(4, 2, T) << endl;
  71. cout << CreateLeftB(5, 3, T) << endl;
  72. cout << CreateLeftB(6, 5, T) << endl;
  73. cout << CreateRightB(7, 5, T) << endl;
  74. cout << CreateRightB(8, 6, T) << endl;
  75.  
  76. cout << "-------------------\n";
  77. cout << "ParentB(6, T): " << ParentB(6, T) << endl;
  78. cout << "LeftChildB(6, T): " << LeftChildB(6, T) << endl;
  79. cout << "RightChildB(6, T): " << RightChildB(6, T) << endl;
  80. cout << "LabelB(6, T): " << LabelB(6, T) << endl;
  81. cout << "ChangeLabelB(2, 6, T): " << ChangeLabelB(2, 6, T) << endl;
  82. cout << "LabelB(6, T): " << LabelB(6, T) << endl;
  83. cout << "RootB(T): " << RootB(T) << endl;
  84. cout << "CreateLeftB(5,6,T): " << CreateLeftB(5,6,T) << endl;
  85. cout << "LeftChildB(6, T): " << LeftChildB(6, T) << endl;
  86. cout << "CreateRightB(5,6,T): " << CreateRightB(5,6,T) << endl;
  87.  
  88. system("pause");
  89. cout << "-------------------\n";
  90. DeleteB(3,T);
  91. for(int i = 1; i < 14; i++)
  92. cout << i << ": " << LabelB(i, T) << endl;
  93.  
  94. system("pause");
  95. cout << "-------------------\n";
  96. InitB(2, T);
  97. for(int i = 1; i < 14; i++)
  98. cout << i << ": " << LabelB(i, T) << endl;
  99. */
  100. }
  101.  
  102. void tab(int t)
  103. {
  104. for(int i = 0; i < t; i++)
  105. cout << " ";
  106. }
  107.  
  108. void Ispis(bTree *node, int t)
  109. {
  110. tab(t);
  111. cout << "--------------------------------------\n";
  112. tab(t);
  113. cout << "Adresa: " << node << "\n";
  114. tab(t);
  115. cout << "Label: " << LabelB(node) << "\n";
  116. tab(t);
  117. cout << "Left: " << LeftChildB(node) << "\n";
  118. if(LeftChildB(node)) Ispis(LeftChildB(node), t+1);
  119. tab(t);
  120. cout << "Right: " << RightChildB(node) << "\n";
  121. if(RightChildB(node)) Ispis(RightChildB(node), t+1);
  122. tab(t);
  123. cout << "--------------------------------------\n";
  124. }
  125.  
  126. void binarno_stablo_pok()
  127. {
  128. bTree *T = InitB(1);
  129. cout << CreateLeftB(2, T) << endl;
  130. cout << CreateRightB(3, T) << endl;
  131. cout << CreateRightB(4, T->l) << endl;
  132. cout << CreateLeftB(5, T->r) << endl;
  133. cout << CreateLeftB(6, T->l->r) << endl;
  134. cout << CreateRightB(7, T->l->r) << endl;
  135. cout << CreateRightB(8, T->r->l) << endl;
  136. system("pause");
  137. Ispis(T, 0);
  138. system("pause");
  139. cout << "\nParentB(*8, T): " << ParentB(T->r->l->r, T);
  140. cout << "\nLeftChildB(*5, T): " << LeftChildB(T->r->l);
  141. cout << "\nRightChildB(*5, T): " << RightChildB(T->r->l);
  142. cout << "\nLabelB(*5, T): " << LabelB(T->r->l);
  143. cout << "\nChangeLabelB(3, *5, T)";
  144. ChangeLabelB(3, T->r->l);
  145. cout << "\nLabelB(*5, T): " << LabelB(T->r->l);
  146. cout << "\nRootB(T): " << RootB(T);
  147. cout << "\nDeleteB(*3, T)\n";
  148. DeleteB(T->r, T);
  149. Ispis(T, 0);
  150.  
  151. DeleteB(T, T);
  152. }
  153.  
  154. int main()
  155. {
  156. //opcenito_stablo();
  157. //binarno_stablo_polje();
  158. binarno_stablo_pok();
  159.  
  160. cout << "\n";
  161. system("pause");
  162. return 0;
  163. }
Add Comment
Please, Sign In to add comment