Posted By


ivahorvat on 01/03/11

Tagged


Statistics


Viewed 601 times
Favorited by 0 user(s)

bstablo_polje.h


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



Copy this code and paste it in your HTML
  1. struct el {
  2. int oz;
  3. int kor;
  4. };
  5.  
  6. struct z {
  7. el elementi[5000];
  8. };
  9.  
  10. typedef int cvor;
  11.  
  12. cvor ParentB(cvor br, z* I) {
  13. if(br == 1) return 0;
  14. if(br%2) br--;
  15. return br/2;
  16. }
  17.  
  18. cvor LeftChildB(cvor br, z* I) {
  19. if(I->elementi[br].kor == 0)
  20. return 0;
  21. if(I->elementi[2*br].kor == 1)
  22. return 2*br;
  23. else return 0;
  24. }
  25.  
  26. cvor RightChildB(cvor br, z* I) {
  27. if(I->elementi[br].kor == 0) return 0;
  28. if(I->elementi[2*br+1].kor == 1) return 2*br+1;
  29. else return 0;
  30. }
  31.  
  32. int LabelB(cvor br, z* I) {
  33. return I->elementi[br].oz;
  34. }
  35.  
  36.  
  37. void ChangeLabelB(int v, cvor br, z* I) {
  38. if(I->elementi[br].kor == 0) return;
  39. I->elementi[br].oz = v;
  40. }
  41.  
  42. cvor RootB(z* I) {
  43. if(I->elementi[1].kor == 0) return 0;
  44. return 1;
  45. }
  46.  
  47. void CreateLeftB(int v, cvor br, z* I) {
  48. if(I->elementi[br].kor == 0 || I->elementi[2*br].kor == 1) {
  49. cout << "Doslo je do pogreske!!" << endl << endl;
  50. return;
  51. }
  52. I->elementi[2*br].kor = 1;
  53. I->elementi[2*br].oz = v;
  54. }
  55.  
  56. void CreateRightB(int v, cvor br, z* I) {
  57. if(I->elementi[br].kor == 0 || I->elementi[2*br+1].kor == 1)
  58. {
  59. cout << "Doslo je do pogreske!!" << endl << endl;
  60. return;
  61. }
  62. I->elementi[2*br+1].kor = 1;
  63. I->elementi[2*br+1].oz = v;
  64. }
  65.  
  66. void DeleteB(cvor br, z* I) {
  67. I->elementi[br].kor = 0;
  68. if (LeftChildB(br, I)) DeleteB(LeftChildB(br, I), I);
  69. if (RightChildB(br, I)) DeleteB(RightChildB(br, I), I);
  70. }
  71.  
  72. z* InitB(int v, z* I) {
  73. if(I) delete I;
  74. I = new z;
  75. for(int i = 0; i < 5000; i++)
  76. I->elementi[i].kor = 0;
  77. I->elementi[1].oz = v;
  78. I->elementi[1].kor = 1;
  79. return I;
  80. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.