一、问题
1
2 3
4 5 6
7
获取某一层的所有节点
二、代码
Java
@Data
public class Node {
private Integer id;
private Node left;
private Node right;
private Integer level;
public Node(Integer id) {
this.id = id;
}
public Node(Integer id, Node left, Node right) {
this.id = id;
this.left = left;
this.right = right;
}
}
@Data
public class Tree {
private Node root;
/**
* 建树 【V80】
*
* 1
* 2 3
* 4 5 6
* 7
*/
public void build() {
Node node7 = new Node(7);
Node node6 = new Node(6);
Node node5 = new Node(5, node7, null);
Node node4 = new Node(4);