Posted By

Dragana_Mlikota on 01/12/14


Tagged

header pokazivac binarno stablo


Versions (?)

BinTree_pointer.h


 / Published in: C++
 

binarno stablo header pokazivac

  1. typedef int labeltype;
  2.  
  3. struct element{
  4. labeltype label;
  5. struct element * left,* right;
  6. };
  7.  
  8. typedef struct element * bnode;
  9. typedef struct element * btree;
  10.  
  11. bool testExistB(bnode n, btree T){
  12. if (n) return true;
  13. return false;
  14. }
  15.  
  16. bnode LeftChildB(bnode n, btree T){
  17. return n->left;
  18. }
  19.  
  20. bnode RightChildB(bnode n, btree T){
  21. return n->right;
  22. }
  23.  
  24. bnode ParentB(bnode n, btree T){
  25. static bnode tekuci = T;
  26. if (tekuci->left==n || tekuci->right==n) return tekuci;
  27. if (tekuci->left) ParentB(LeftChildB(tekuci, T), T);
  28. if (tekuci->right) ParentB(RightChildB(tekuci, T), T);
  29. }
  30.  
  31. labeltype LabelB(bnode n, btree T){
  32. return n->label;
  33. }
  34.  
  35. void ChangeLabelB(labeltype x, bnode n, btree T){
  36. n->label = x;
  37. }
  38.  
  39. bnode RootB(btree T){
  40. return T;
  41. }
  42.  
  43. void CreateLeftB(labeltype x, bnode n, btree T){
  44. if (n->left) {
  45. cout << "Nije moguce stvoriti cvor, cvor je vec zauzet\n";
  46. return;
  47. }
  48. bnode novi = new element;
  49. novi->label = x;
  50. novi->left = NULL;
  51. novi->right = NULL;
  52. n->left = novi;
  53. }
  54.  
  55. void CreateRightB(labeltype x, bnode n, btree T){
  56. if (n->right) {
  57. cout << "Nije moguce stvoriti cvor, cvor je vec zauzet\n";
  58. return;
  59. }
  60. bnode novi = new element;
  61. novi->label = x;
  62. novi->left = NULL;
  63. novi->right = NULL;
  64. n->right = novi;
  65. }
  66.  
  67. void DeleteB(bnode n, btree T){
  68. if (n->left) DeleteB(LeftChildB(n, T), T);
  69. if (n->right) DeleteB(RightChildB(n, T), T);
  70. delete n;
  71.  
  72. }
  73.  
  74.  
  75. btree InitB(labeltype x, btree T){
  76. T = new element;
  77. T->label = x;
  78. T->left = NULL;
  79. T->right = NULL;
  80. return T;
  81. }

Report this snippet  

You need to login to post a comment.