Posted By


tturek on 01/03/14

Tagged


Statistics


Viewed 67 times
Favorited by 0 user(s)

binarno_pokazivaci


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

eto pokazivaca


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.