各ノードを文字列値に設定するBSTを作成しましたが、ツリーを検索する方法はあるのですが、一度に1つの値だけを検索する方法があるのだろうかと思いました。だから、ノードの文字列が "トラック"だったと言うと、ツリーを検索して "t"を返す方法はありますか?これは、ツリーを構築するための私が持っているコードです:BSTで検索する
public class BinaryTree {
public Node root;
public BinaryTree tree;
public static int pos;
public static Node[] theArray;
private static class Node {
Node left;
Node right;
String data;
Node(String s) {
left = null;
right = null;
data = s;
}
}
public BinaryTree plantTree(ArrayList<String> dict) {
tree = new BinaryTree();
Collections.shuffle(dict);
for (String s : dict) {
s.toUpperCase();
tree.add(s);
}
return tree;
}
/**
* Creates an empty binary tree
*/
public BinaryTree() {
root = null;
}
public void add(String data) {
root = add(root, data);
}
private Node add(Node node, String data) {
if (node == null) {
node = new Node(data);
} else {
if (data.compareTo(node.data) > 0) {
node.left = add(node.left, data);
} else {
node.right = add(node.right, data);
}
}
return (node);
}
}
質問が不明です – Adrian