1.链式存储这就是链式存储
代码如下
节点Node
class Node{
private int value;
private Node left;
private Node right;
public Node() {
this.left = null;
this.right = null;
}
public Node(int value) {
this.left = null;
this.value= value;
this.right = null;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public Node getLeft() {
return left;
}
public void setLeft(Node left) {
this.left = left;
}
public Node getRight() {
return right;
}
public void setRight(Node right) {
this.right = right;
}
}
树
public class BinaryTree {
Node root;
public BinaryTree(Node root) {
this.root = root;
}
public Node getRoot() {
return root;
}
public void setRoot(Node root) {
this.root = root;
}
}