public class RedBlackTree<T extends Comparable<? super T>> extends Object implements ISortTree<T>
| 构造器和说明 |
|---|
RedBlackTree()
构造器
初始化一颗空树
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(T data)
添加元素
|
boolean |
contains(T data)
是否包含
|
int |
getHeight()
最大深度
|
T |
getMaxValue()
获取最大值
|
T |
getMinValue()
获取最小值
|
int |
getSize()
返回元素的个数
|
List<T> |
inOrder()
中序遍历:即左-根-右遍历,对于给定的二叉树根,寻找其左子树;对于其左子树的根,再去寻找其左子树;递归遍历,直到寻找最左边的节点i,其必然为叶子,然后遍历i的父节点,再遍历i的兄弟节点。
|
boolean |
isBalanced()
是否为平衡树
|
boolean |
isEmpty()
是否为空
|
List<T> |
levelOrder()
层级遍历
|
List<List<T>> |
pathList()
获取所有路径列表
从根节点,到叶子节点的路径
|
List<T> |
postOrder()
后序遍历:即左-右-根遍历,不再详述。
|
List<T> |
preOrder()
先序遍历:即根-左-右遍历,不再详述。
|
void |
print()
以树的形式打印出来元素
2
/ \
2 3
/ /
1 3
/
1
|
boolean |
remove(T data)
删除节点
|
public boolean contains(T data)
ISortTreecontains 在接口中 ISortTree<T extends Comparable<? super T>>data - 元素public void add(T data)
ISortTreeadd 在接口中 ISortTree<T extends Comparable<? super T>>data - 元素public boolean remove(T data)
ISortTreeremove 在接口中 ISortTree<T extends Comparable<? super T>>data - 元素public int getSize()
ISortTreegetSize 在接口中 ISortTree<T extends Comparable<? super T>>public boolean isEmpty()
ISortTreeisEmpty 在接口中 ISortTree<T extends Comparable<? super T>>public int getHeight()
ISortTreegetHeight 在接口中 ISortTree<T extends Comparable<? super T>>public T getMinValue()
ISortTreegetMinValue 在接口中 ISortTree<T extends Comparable<? super T>>public T getMaxValue()
ISortTreegetMaxValue 在接口中 ISortTree<T extends Comparable<? super T>>public List<T> inOrder()
ISortTreeinOrder 在接口中 ISortTree<T extends Comparable<? super T>>public List<T> preOrder()
ISortTreepreOrder 在接口中 ISortTree<T extends Comparable<? super T>>public List<T> postOrder()
ISortTreepostOrder 在接口中 ISortTree<T extends Comparable<? super T>>public List<T> levelOrder()
ISortTreelevelOrder 在接口中 ISortTree<T extends Comparable<? super T>>public List<List<T>> pathList()
ISortTreepathList 在接口中 ISortTree<T extends Comparable<? super T>>public void print()
ISortTreeprint 在接口中 ISortTree<T extends Comparable<? super T>>public boolean isBalanced()
ISortTreeisBalanced 在接口中 ISortTree<T extends Comparable<? super T>>Copyright © 2020. All rights reserved.