トラバーサルの 1 つを変更する必要があると思います。最小から最大まで印刷するものを変更してみましたが、これはこれです
private void printTree(BinaryTreeNode t) {
if (t != null) {
printTree(t.llink);
System.out.print(" " + t.info);
printTree(t.rlink);
}
}
しかし、うまくいきませんでした。次に何を試すべきか、まだ悩んでいます。これは私が使用している二分探索木です:
public class BinarySearchTree extends BinaryTree {
//Default constructor.
//Postcondition: root = null;
public BinarySearchTree() {
super();
}
//Copy constructor.
public BinarySearchTree(BinarySearchTree otherTree) {
super(otherTree);
}
public class BinaryTree {
//Definition of the node
protected class BinaryTreeNode {
DataElement info;
BinaryTreeNode llink;
public DataElement getInfo() {
return info;
}
public BinaryTreeNode getLlink() {
return llink;
}
public BinaryTreeNode getRlink() {
return rlink;
}
BinaryTreeNode rlink;
}
protected BinaryTreeNode root;
//Default constructor
//Postcondition: root = null;
public BinaryTree() {
root = null;
}
//Copy constructor
public BinaryTree(BinaryTree otherTree) {
if (otherTree.root == null) //otherTree is empty.
{
root = null;
}
else {
root = copy(otherTree.root);
}
}
public BinaryTreeNode getRoot() {
return root;
}