现在我有一个BST,我需要按升序和降序打印。升序部分工作正常,但降序仅打印文件的第一个元素30次(文件中30个不同的元素)。我不确定问题是什么,感谢任何帮助!!!
private Node root;
public void traverse(int traverseType, DataBaseArray DBA){
switch(traverseType){
case 0: descendingOrder(root, DBA);break;
case 1: ascendingOrder(root,DBA);break;
}
System.out.println();
}
private void ascendingOrder(Node localRoot, DataBaseArray DBA){
if(localRoot != null){
ascendingOrder(localRoot.leftChild, DBA);
System.out.println(DBA.toString(localRoot.getWhere));
ascendingOrder(localRoot.rightChild,DBA);
}
}
private void descendingOrder(Node localRoot, DataBaseArray DBA){
if(localRoot != null){
descendingOrder(localRoot.rightChild,DBA);
System.out.println(DBA.toString(localRoot.getWhere()));
descendingOrder(localRoot.leftChild,DBA);
}
}
public void displayList(Tree tree, int x) {
tree.traverse(x,DBA);
}