二叉树的分类(按存储结构)
树的分类(按存储结构)
顺序存储(用数组表示(静态二叉树))
链式存储
一些特别的二叉根:
完全二叉树,平衡二叉树(AVL),线索二叉树,三叉的(带父亲的指针)
二叉搜索树或者叫二叉 查找树(BST)
所用二叉树如下图所示:
二叉树的Java实现(链式存储结构)
class TreeNode {
private int key = 0;
private String data = null;
private boolean isVisted = false;
private TreeNode leftChild = null;
private TreeNode rightChild = null;
public TreeNode(){
}
public TreeNode(int key, String data){
this.key = key;
this.data = data;
this.leftChild = null;
this.rightChild = null;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public TreeNode getLeftChild() {
return leftChild;
}
public void setLeftChild(TreeNode leftChild) {
this.leftChild = leftChild;
}
public TreeNode getRightChild() {
return rightChild;
}
public void setRightChild(TreeNode rightCh