Kod:
public boolean search(String s) {
if (current.compareKeys(s)) {
System.out.println("yup");
return true;
}
if (right != null)
right.search(s);
if (left != null)
left.search(s);
System.out.println("nope");
return false;
}
Kod:
///METODA COMPARE KEYS Z KLASY PAIR KTORA PRZECHOWUJE String key i dou
public boolean compareKeys(String s) {
if (key.equals(s)) {
return true;
}
return false;
}
Kod:
nope
nope
yup
nope
nope
nope
nope
nope
nope
Kod:
define BST_TREE_SEARCH (Node, Key):
if (Node == NULL) or (Node->Key == Key)
return Node
if Key < Node->Key
return BST_TREE_SEARCH (Node->Left, Key)
return BST_TREE_SEARCH (Node->Right, Key)
mecze się nad tym już którąś godzine, a jestem pewien ze rozwiązanie jest jakieś mega proste. nakierujcie mnie proszę!
edit. moglbym zrobic np zmienna found i zrobic cos takiego
Kod:
boolean found = false;
public boolean search3(string s) {
found = false;
root.search2(s);
return found;
}
Zakładki