Posted By

sasposlon123 on 01/13/14


Tagged


Versions (?)

binarno stablo pokazivaci


 / Published in: C++
 

pokazivaci binarno

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct btree {
  5. char oznaka;
  6. btree *lijevo, *desno;
  7. };
  8. typedef struct btree *element;
  9.  
  10. btree *LeftChildB(btree *n, btree *B){
  11. return n->left;
  12. }
  13.  
  14. btree *RightChildB(btree *n, btree *B){
  15. return n->right;
  16. }
  17. void CreateLeftB(char x, btree *n, btree *B){
  18. if (n->left)
  19. cout << "Lijevo dijete vec postoji" << endl;
  20. else{
  21. n->left = new btree;
  22. n->left->label=x;
  23. n->left->left=NULL;
  24. n->left->right=NULL;
  25. }
  26. }
  27. void ChangeLabelB(char x, btree *n, btree *B){
  28. n->label=x;
  29. }
  30. void CreateRightB(char x, btree *n, btree *B){
  31. if (n->desno)
  32. cout << "Desno dijete vec postoji" << endl;
  33. else{
  34. n->right = new btree;
  35. n->right->label=x;
  36. n->right->left=NULL;
  37. n->right->right=NULL;
  38. }
  39. }
  40. char LabelB(btree *n, btree *B){
  41. return n->label;
  42. }
  43. btree *ParentB(btree *n, btree *B){
  44. static btree *node;
  45. static bool nadjen=false;
  46. if (B->left==n || B->right==n){
  47. nadjen=true;
  48. cvor=B;
  49. }
  50. if (nadjen)
  51. return node;
  52. if (B->left)
  53. ParentB(n,B->left);
  54. if (B->right)
  55. ParentB(n,B->right);
  56. }
  57. btree *RootB(btree *B){
  58. return B;
  59. }
  60. void DeleteB(btree *n, btree *B){
  61. btree *parent = ParentB(n,B);
  62. if (parent->left==n) parent->right=NULL;
  63. else parent->right=NULL;
  64.  
  65. if (n->left)
  66. DeleteB(n->left,B);
  67. if (n->right)
  68. DeleteB(n->right,B);
  69. delete n;
  70.  
  71. }
  72. btree *InitB(int x, btree *B){
  73. B=new btree;
  74. B->left=NULL;
  75. B->right=NULL;
  76. B->label=x;
  77. return B;
  78. }

Report this snippet  

You need to login to post a comment.