/ Published in: C++
Binarno stablo pretrazivanja
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
bool ExistsLeftChild(node *T){ if(T->lijevo) return true; else return false; } bool ExistsRightChild(node *T){ if(T->desno) return true; else return false; } void insert_BS(int m, node *T){ bool dalje = true; node *t = T; do{ if(m > t->label){ if(ExistsRightChild(t)) t = t->desno; else { CreateRightB(m, t); dalje = false; } } else if(m < t->label){ if(ExistsLeftChild(t)) t = t->lijevo; else { CreateLeftB(m, t); dalje = false; } } else dalje = false; }while(dalje); } void bin_search(int k, node *T){ if(T->label == k){ cout << "Trazeni element JE PRONADJEN!"<<endl; return; } if(k > T->label){ if(ExistsRightChild(T)) bin_search(k, T->desno); else cout << "Trazeni element NE POSTOJI!"<<endl; } if(k < T->label){ if(ExistsLeftChild(T)) bin_search(k, T->lijevo); else cout << "Trazeni element NE POSTOJI!"<<endl; } }