我想我必须修改其中一个遍历。我尝试修改一个从最小到最大的打印,这就是这个
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;
}