树的常用术语
二叉树
满二叉树
前序遍历
中序遍历
后序遍历
顺序存储二叉树在一维数组中的存储特特点
实现实例配图
运行结果
class Node
public class Node {
private int no;
private String name;
private Node left;
private Node right;
public Node(int no, String name) {
this.no = no;
this.name = name;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
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;
}
@Override
public String toString() {
return "Node{" +
"no=" + no +
", name='" + name + '\'' +
", left=" + left +
", right=" + right +
'}';
}
/**
* 定义前序遍历(先序遍历)
*/
public void perSelect(){
System.out.println(this);
if(this.left!=null){
this.left.perSelect();
}
if(this.right!=null){
this.right.perSelect();
}
}
/**
* 定义中序遍历
*/
public void infixSelect(){
if(this.left!=null){
this.left.infixSelect();
}
System.out.println(this);
if(this.right