Posted By

akljaic on 01/19/15


Tagged

tree binary


Versions (?)

pretrazivanje.h


 / Published in: C++
 

URL: asdf

asdf

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void AddElement(int x, int root, btree *T){
  5. bool ponovi = true;
  6. do{
  7. if(x < LabelB(root,T)){
  8. if(ExistLeftChild(root,T))
  9. root = LeftChildB(root,T);
  10. else{
  11. CreateLeftB(x,root,T);
  12. ponovi = false;
  13. }
  14. }
  15. else if(x > LabelB(root,T)){
  16. if(ExistRightChild(root,T))
  17. root = RightChildB(root,T);
  18. else{
  19. CreateRightB(x,root,T);
  20. ponovi = false;
  21. }
  22. }
  23. }while(ponovi);
  24. }
  25.  
  26. bool Find(int x, int root, btree *T){
  27. bool ponovi = true;
  28. bool nadjen = false;
  29. do{
  30. if(x == LabelB(root,T)){
  31. nadjen = true;
  32. ponovi = false;
  33. }
  34. if(x < LabelB(root,T)){
  35. if(ExistLeftChild(root,T))
  36. root = LeftChildB(root,T);
  37. else
  38. ponovi = false;
  39. }
  40. else if (x > LabelB(root,T)){
  41. if(ExistRightChild(root,T))
  42. root = RightChildB(root,T);
  43. else
  44. ponovi = false;
  45. }
  46. }while(ponovi);
  47. return nadjen;
  48. }

Report this snippet  

You need to login to post a comment.