Posted By


ksimunovic on 01/19/15

Tagged


Statistics


Viewed 423 times
Favorited by 0 user(s)

bstablo_polje.h


/ Published in: C++
Save to your folder(s)

bstablo_polje.h


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. char lab[50];
  5. bool alocirano = false;
  6.  
  7. struct el
  8. {
  9. char naziv[50];
  10. bool last;
  11. };
  12.  
  13. struct sp
  14. {
  15. el elementi[1000];
  16. };
  17. void InitB(char naziv[50], sp *stablo)
  18. {
  19. for(int i=0;i<999;i++)
  20. stablo->elementi[i].last = 0;
  21.  
  22. stablo->elementi[1].last = 1;
  23. strcpy(stablo->elementi[1].naziv, naziv);
  24. alocirano = true;
  25. }
  26.  
  27. bool ParentB(int n, sp *stablo)
  28. {
  29. if(n==1)
  30. {
  31. cout << "NULL cvor" << endl;
  32. return 0;
  33. }
  34.  
  35. strcpy(lab, stablo->elementi[n/2].naziv);
  36.  
  37. return 1;
  38. }
  39. bool CreateLeftB(char naziv[50], int n, sp *stablo)
  40. {
  41. if(stablo->elementi[n].last = 0)
  42. {
  43. cout << "Cvor ne postoji!" << endl;
  44. return 0;
  45. }
  46.  
  47. if(stablo->elementi[n*2].last == 1)
  48. {
  49. cout << "Pogreska!" << endl;
  50. return 0;
  51. }
  52.  
  53. stablo->elementi[n*2].last = 1;
  54. strcpy(stablo->elementi[n*2].naziv, naziv);
  55.  
  56. return 1;
  57. }
  58. bool CreateRightB(char naziv[50], int n, sp *stablo)
  59. {
  60. if(stablo->elementi[n].last = 0)
  61. {
  62. cout << "Cvor ne postoji!" << endl;
  63. return 0;
  64. }
  65.  
  66. if(stablo->elementi[n*2+1].last==1)
  67. {
  68. cout << "Pogreska!" << endl;
  69. return 0;
  70. }
  71.  
  72. stablo->elementi[n*2+1].last = 1;
  73. strcpy(stablo->elementi[n*2+1].naziv, naziv);
  74.  
  75. return 1;
  76. }
  77. bool DeleteB(int n, sp *stablo)
  78. {
  79. stablo->elementi[n].last = 0;
  80. stablo->elementi[n].naziv[0] = '\0';
  81. int j=n*2,k=n*2+1;
  82. if(j < 1000)
  83. DeleteB(j, stablo);
  84.  
  85. if(k < 1000)
  86. DeleteB(k, stablo);
  87.  
  88. return 0;
  89. }
  90.  
  91. void ChangeLabelB(int n, sp *stablo)
  92. {
  93. strcpy(lab, stablo->elementi[n].naziv);
  94. }
  95.  
  96. void ChangeLabelT(char naziv[50], int n, sp *stablo)
  97. {
  98. strcpy(stablo->elementi[n].naziv, naziv);
  99. }
  100.  
  101. bool RootB(sp*stablo)
  102. {
  103. if(!alocirano)
  104. {
  105. cout << "Stablo je prazno!" << endl;
  106. return 0;
  107. }
  108.  
  109. strcpy(lab, stablo->elementi[1].naziv);
  110.  
  111. return 1;
  112. }
  113. bool LeftChildB(int n, sp *stablo)
  114. {
  115. if(stablo->elementi[n*2].last == 0)
  116. {
  117. cout << "Nema lijevog djeteta!" << endl;
  118. return 0;
  119. }
  120.  
  121. strcpy(lab, stablo->elementi[n*2].naziv);
  122.  
  123. return 1;
  124. }
  125. bool RightChildB(int n, sp *stablo)
  126. {
  127. if(stablo->elementi[n*2+1].last == 0)
  128. {
  129. cout << "Nema desnog djeteta!" << endl;
  130. return 0;
  131. }
  132.  
  133. strcpy(lab, stablo->elementi[n*2+1].naziv);
  134.  
  135. return 0;
  136. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.