Posted By

dare10 on 01/20/14


Tagged


Versions (?)

Glavni program


 / Published in: C++
 

Demonstracija - Glavni program u kojem se pozivaju funkcije iz header datoteka

  1. #include <iostream>
  2. #include "prvo dijete-sljedeci brat.h"
  3. #include "binarno_pokazivac.h"
  4. //#include "binarno_polje.h"
  5. #include "preorder postorder inorder.h"
  6. using namespace std;
  7. int main () {
  8. int n,kor,a,b,c,d,e,f,g,h,i,j,k;
  9. do{
  10. cout << "Demonstracija" << endl << endl;
  11. cout << "1.Prvo dijete sljedeci brat te preorder postorder inorder" << endl;
  12. cout << "2.Binarno stablo" << endl;
  13. cout << "3.Izlaz" << endl << endl;
  14. cin >> n;
  15. switch(n){
  16. case 1:{
  17. system("cls");
  18. cout << "Implementacija stabla prvo dijete sljedeci brat" << endl << endl;
  19. cout << "Unesite korijen stabla: ";
  20. cin >> kor;
  21. tree *STAB=InitT(kor,STAB);
  22. cout << "RootB: " << RootT(STAB) << endl;
  23. cout << "Unesite 3 potomka za korijen (" << RootT(STAB) << ")"<< endl;
  24. cin >>a>>b>>c;
  25. CreateT(a,RootT(STAB),STAB);
  26. CreateT(b,RootT(STAB),STAB);
  27. CreateT(c,RootT(STAB),STAB);
  28. cout << "Unesite 2 potomka za cvor: " << a << endl;
  29. cin >> d >> e;
  30. CreateT(d,a,STAB);
  31. CreateT(e,a,STAB);
  32. cout << "Unesite 2 potomka za cvor: " << b << endl;
  33. cin >> f >> g;
  34. CreateT(f,b,STAB);
  35. CreateT(g,b,STAB);
  36. cout << "Unesite 3 potomka za cvor: " << c << endl;
  37. cin >> i >> j >> k;
  38. CreateT(i,c,STAB);
  39. CreateT(j,c,STAB);
  40. CreateT(k,c,STAB);
  41. cout << endl << "Prvo dijete korijena (" << RootT(STAB) << ") :" << FirstChildT(RootT(STAB),STAB) << endl;
  42. cout << "Braca cvora: " << FirstChildT(RootT(STAB),STAB) << " su " << NextSiblingT(FirstChildT(RootT(STAB),STAB),STAB) << " i "<<
  43. NextSiblingT(NextSiblingT(FirstChildT(RootT(STAB),STAB),STAB),STAB) << endl;
  44. cout << "Roditelj cvora " << a << " je " << ParentT(a,STAB) << endl;
  45. cout << "Oznaka cvora " << b << " je " << LabelT(b,STAB) << endl;
  46. cout << "Unesite novu oznaku za cvor " << b << ": ";
  47. char novi;
  48. cin >> novi;
  49. ChangeLabelT(novi,b,STAB);
  50. cout << "Nova oznaka cvora " << b << " je " << LabelT(b,STAB) << endl << endl;
  51. cout << "Preorder: " << endl;
  52. Preorder(STAB);
  53. cout << endl;
  54. STAB->root = kor;
  55. cout << "Inorder: " << endl;
  56. Inorder(STAB);
  57. cout << endl;
  58. STAB->root = kor;
  59. cout << "Postorder: " << endl;
  60. Postorder(STAB);
  61. system("cls");
  62. break;
  63. }
  64. case 2:{
  65. system("cls");
  66. cout << "Binarno stablo" << endl << endl;
  67. cout << "Unesite korijen binarnog stabla: ";
  68. cin >> kor;
  69. node *STAB=InitB(kor,STAB);
  70. cout << "Korijen: " << LabelB(RootB(STAB)) << endl;
  71. cout << "Lijevo dijete korijena(" << LabelB(RootB(STAB)) << "): ";
  72. cin >> a;
  73. CreateLeftB(a,RootB(STAB));
  74. cout << "Desno dijete korijena(" << LabelB(RootB(STAB)) << "): ";
  75. cin >> b;
  76. CreateRightB(b,RootB(STAB));
  77. cout << "Unesite lijevo te desno dijete lijevog djeteta korijena(" << LabelB(LeftChildB(RootB(STAB))) << "): " << endl;
  78. cin >> d>>c;
  79. CreateLeftB(d,LeftChildB(RootB(STAB)));
  80. CreateRightB(c,LeftChildB(RootB(STAB)));
  81. cout << "Unesite lijevo dijete cvora: " << LabelB(LeftChildB(LeftChildB(RootB(STAB)))) << endl;
  82. cin >> e;
  83. CreateLeftB(e,LeftChildB(LeftChildB(RootB(STAB))));
  84. cout << "Unesite novu oznaku korijena: ";
  85. cin >> f;
  86. ChangeLabelB(f,RootB(STAB));
  87. cout << "Ispis" << endl << endl;
  88. cout << "Korijen: " << LabelB(RootB(STAB)) << endl;
  89. cout << "Lijevo dijete korijena: " << LabelB(LeftChildB(RootB(STAB))) << endl;
  90. cout << "Desno dijete korijena: " << LabelB(RightChildB(RootB(STAB))) << endl;
  91. cout << "Lijevo dijete cvora: " << LabelB(LeftChildB(RootB(STAB))) << ": " << LabelB(LeftChildB(LeftChildB(RootB(STAB)))) << endl;
  92. cout << "Desno dijete cvora: " << LabelB(LeftChildB(RootB(STAB))) << ": " << LabelB(RightChildB(LeftChildB(RootB(STAB)))) << endl;
  93. cout << "Lijevo dijete cvora: " << LabelB(LeftChildB(LeftChildB(RootB(STAB)))) << ": " << LabelB(LeftChildB(LeftChildB(LeftChildB(RootB(STAB))))) << endl;
  94. system("cls");
  95. break;
  96. }
  97. }
  98. }while(n!=3);
  99. return 0;
  100. }

Report this snippet  

You need to login to post a comment.