Posted By


brumihali on 01/19/15

Tagged


Statistics


Viewed 57 times
Favorited by 0 user(s)

b_stablo_pretrazivanja.h


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

Binarno stablo pretrazivanja


Copy this code and paste it in your HTML
  1. bool ExistsLeftChild(node *T){
  2. if(T->lijevo) return true;
  3. else return false;
  4. }
  5.  
  6. bool ExistsRightChild(node *T){
  7. if(T->desno) return true;
  8. else return false;
  9. }
  10.  
  11. void insert_BS(int m, node *T){
  12. bool dalje = true;
  13. node *t = T;
  14. do{
  15. if(m > t->label){
  16. if(ExistsRightChild(t)) t = t->desno;
  17. else {
  18. CreateRightB(m, t);
  19. dalje = false;
  20. }
  21. }
  22. else if(m < t->label){
  23. if(ExistsLeftChild(t)) t = t->lijevo;
  24. else {
  25. CreateLeftB(m, t);
  26. dalje = false;
  27. }
  28. }
  29. else dalje = false;
  30. }while(dalje);
  31. }
  32.  
  33. void bin_search(int k, node *T){
  34. if(T->label == k){
  35. cout << "Trazeni element JE PRONADJEN!"<<endl;
  36. return;
  37. }
  38. if(k > T->label){
  39. if(ExistsRightChild(T)) bin_search(k, T->desno);
  40. else cout << "Trazeni element NE POSTOJI!"<<endl;
  41. }
  42. if(k < T->label){
  43. if(ExistsLeftChild(T)) bin_search(k, T->lijevo);
  44. else cout << "Trazeni element NE POSTOJI!"<<endl;
  45. }
  46. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.