Вот код для печати заказовМои обхода двоичного дерева поиска: общественного класса BSTPrint {Почему указатели отображаются вместо строки в моем обходном пути BST?
public void printInorder(BSTNode root){
if (root!=null){
printInorder(root.getLeftNode());
System.out.println(root.getNodeValue());
printInorder(root.getRightNode());
}
}
public static void main(String[] argc){
BSTPrint bstPrint = new BSTPrint();
BSTNode<String> root=new BSTNode<String>();
root.setNodeValue("5");
BSTNode<String> rootLeft= new BSTNode<String>();
rootLeft.setNodeValue("3");
root.setLeftNode(rootLeft);
BSTNode<String> rootRight= new BSTNode<String>();
rootRight.setNodeValue("8");
root.setRightNode(rootRight);
bstPrint.printInorder(root);
}
}
Вот класс BSTNode:
public class BSTNode<E> {
private E value;
private BSTNode<E> leftNode=null;
private BSTNode<E> rightNode=null;
public BSTNode getLeftNode(){
return this.leftNode;
}
public void setLeftNode(BSTNode rootLeft){
BSTNode newLeftNode=new BSTNode();
newLeftNode.leftNode=null;
this.leftNode=newLeftNode;
newLeftNode.value=rootLeft;
}
public BSTNode getRightNode(){
return this.rightNode;
}
public void setRightNode(BSTNode rootRight){
BSTNode newRightNode=new BSTNode();
newRightNode.rightNode=null;
this.rightNode=newRightNode;
newRightNode.value=rootRight;
}
public E getNodeValue(){
return this.value;
}
public void setNodeValue(E value){
this.value=value;
}
}
Почему я вижу мой результат, как следующее ?
[email protected]
5
[email protected]
вместо
3
5
8
Ваши дженерики все испорчены. – Rishav
Полностью несвязанный, но вот как ваш код должен выглядеть с надлежащими дженериками. http://ix.io/l9P – Rishav