Posted By


mateocindric on 01/19/15

Tagged


Statistics


Viewed 439 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. int bstablo[1000];
  5.  
  6. void InitB(int n, int bstablo[]){
  7. bstablo[1]=n;
  8. for(int i=2;i<1000;i++)
  9. bstablo[i]=-1;
  10. }
  11.  
  12. int LabelB(int n, int bstablo[]){
  13. return bstablo[n];
  14. }
  15.  
  16. void ChangeLabelB(int x,int n, int bstablo[]){
  17. bstablo[n]=x;
  18. }
  19.  
  20. int RootB(int bstablo[]){
  21. return 1;
  22. }
  23.  
  24. int ParentB(int n, int bstablo[]){
  25. if(n==RootB(bstablo))
  26. return -1;
  27. if(n%2)
  28. return (n-1)/2;
  29. else
  30. return n/2;
  31. }
  32.  
  33. int LeftChildB(int n,int bstablo[]){
  34. if(LabelB(n*2,bstablo)==-1)
  35. return -1;
  36. else
  37. return n*2;
  38. }
  39.  
  40. int RightChildB(int n, int bstablo[]){
  41. if(LabelB(n*2+1,bstablo)==-1)
  42. return -1;
  43. else
  44. return n*2+1;
  45. }
  46.  
  47. bool CreateRightB(int x, int n, int bstablo[]){
  48. if(RightChildB(n, bstablo)!=-1)
  49. return false;
  50. bstablo[n*2+1]=x;
  51. return true;
  52. }
  53.  
  54. bool CreateLeftB(int x, int n, int bstablo[]){
  55. if(LeftChildB(n, bstablo)!=-1)
  56. return false;
  57. bstablo[n*2]=x;
  58. return true;
  59. }
  60.  
  61. void DeleteB(int n, int bstablo[]){
  62. if(LeftChildB(n, bstablo)!=-1)
  63. DeleteB(LeftChildB(n, bstablo),bstablo);
  64. if(RightChildB(n, bstablo)!=-1)
  65. DeleteB(RightChildB(n, bstablo),bstablo);
  66. bstablo[n]=-1;
  67. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.