Posted By


mateom11 on 01/19/15

Tagged


Statistics


Viewed 43 times
Favorited by 0 user(s)

Binarno_stablo_pretrazivanje.h


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

Binarno_stablo_pretrazivanje


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. #include "binarno_polje.h"
  3. using namespace std;
  4.  
  5. void dodaj_element(int x,node korjen, btree T){
  6.  
  7. bool ponovi=true;
  8. do{
  9. if (x < LabelB(korjen,T)){
  10. if (ExistLeftChild(korjen,T))
  11. korjen=LeftChildB(korjen,T);
  12. else{
  13. CreateLeftB(x,korjen,T);
  14. ponovi=false;
  15. }
  16. }
  17. else if(x>LabelB(korjen,T)){
  18. if (ExistRightChild(korjen,T))
  19. korjen=RightChildB(korjen,T);
  20. else{
  21. CreateRightB(x,korjen,T);
  22. ponovi =false;
  23. }
  24.  
  25. }
  26.  
  27. if(x==LabelB(korjen,T)) ponovi=false;
  28.  
  29. }while(ponovi);
  30. }
  31.  
  32. bool pretrazi(int x,node korjen,btree T){
  33. bool ponovi=true;
  34. bool nadjen = false;
  35. do{
  36. if( x==LabelB(korjen,T)) {
  37. nadjen = true;
  38. ponovi= false;
  39. }
  40. if (x < LabelB(korjen,T)){
  41. if (ExistLeftChild(korjen,T))
  42. korjen=LeftChildB(korjen,T);
  43. else ponovi=false;
  44. }
  45. else if(x>LabelB(korjen,T)){
  46. if (ExistRightChild(korjen,T))
  47. korjen=RightChildB(korjen,T);
  48. else ponovi =false;
  49. }
  50. }while(ponovi);
  51.  
  52. return nadjen;
  53. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.