Posted By


brumihali on 01/19/15

Tagged


Statistics


Viewed 309 times
Favorited by 0 user(s)

b_stablo_pokazivac.h


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

Binarno stablo pokazivac


Copy this code and paste it in your HTML
  1. struct node{
  2. int label;
  3. node *lijevo, *desno;
  4. };
  5.  
  6. node *InitB(int x, node *T){
  7. T = new node;
  8. T->lijevo = T->desno = NULL;
  9. T->label = x;
  10. return T;
  11. }
  12.  
  13. node *RootB(node *T){
  14. return T;
  15. }
  16.  
  17. node *ParentB(int n, node *T){
  18. if(T->label == n) return NULL;
  19. if(T->lijevo){
  20. if(T->lijevo->label == n) return T;
  21. ParentB(n, T->lijevo);
  22. }
  23. if(T->desno){
  24. if(T->desno->label == n) return T;
  25. ParentB(n, T->desno);
  26. }
  27. }
  28.  
  29. node *LeftChildB(node *T){
  30. return T->lijevo;
  31. }
  32.  
  33. node *RightChildB(node *T){
  34. return T->desno;
  35. }
  36.  
  37. int LabelB(node *T){
  38. return T->label;
  39. }
  40.  
  41. void ChangeLabelB(int x, node *T){
  42. T->label = x;
  43. }
  44.  
  45. void CreateLeftB(int x, node *T){
  46. if(T->lijevo) cout << "Cvor vec ima dijete!"<<endl;
  47. else{
  48. node *novi = new node;
  49. novi->label = x;
  50. novi->lijevo = novi->desno = NULL;
  51. T->lijevo = novi;
  52. }
  53. }
  54.  
  55. void CreateRightB(int x, node *T){
  56. if(T->desno) cout << "Cvor vec ima dijete!"<<endl;
  57. else{
  58. node *novi = new node;
  59. novi->label = x;
  60. novi->lijevo = novi->desno = NULL;
  61. T->desno = novi;
  62. }
  63. }
  64.  
  65. void DeleteB(node *n, node *T){
  66. if(n->lijevo != NULL) DeleteB(n->lijevo, T);
  67. if(n->desno != NULL) DeleteB(n->desno, T);
  68. delete n;
  69. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.