package DataStructure;
import java.util.Stack;
public class BiTree {//è¿ä¸ªä»£ç æ¯éçï¼ç®åè½åä¸è¶³ï¼æ æ³çº æ£ 2022.3.24
public class Node {
private Object value;
private Node left;
private Node right;
public Node(){}
public Node(Object value,Node left,Node right) {
this.value = value;
this.left = left;
this.right = right;
}
public Node(Object value){
this.value = value;
}
public Object getValue() {
return value;
}
public Node getLeft() {
return left;
}
public Node getRight() {
return right;
}
public void setValue(Object value) {
this.value = value;
}
public void setLeft(Node left) {
this.left = left;
}
public void setRight(Node right) {
this.right = right;
}
}
private Node root;
private int index = 0;
public BiTree(String str) {//å
åºéå建æ ç´æ¥åå¨æé æ¹æ³éï¼åC++ä¸ä¸æ ·
char c = str.charAt(index++);
if(c != '#'){
root = new Node(c);
root.left = new BiTree(str).root;
root.right = new BiTree(str).root;
} else root = null;//æé 彿°åªæè¿åå¼
}
public void preRootTraverse(){
Node T = root;
if(T != null) {
Stack