public class BinarySearchTree<V extends Comparable<? super V>> extends Object implements ISortTree<V>
| 构造器和说明 |
|---|
BinarySearchTree() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(V data)
Inserts the given data into the binary tree.
|
boolean |
contains(V data)
* Returns true if the given target is in the binary tree
|
TreeNode<V> |
getSuccessor(TreeNode<V> delNode)
寻找中继节点
|
List<V> |
inOrder()
中序遍历:即左-根-右遍历,对于给定的二叉树根,寻找其左子树;对于其左子树的根,再去寻找其左子树;递归遍历,直到寻找最左边的节点i,其必然为叶子,然后遍历i的父节点,再遍历i的兄弟节点。
|
List<V> |
levelOrder()
层级遍历
|
int |
maxDepth()
最大深度
|
V |
maxValue()
获取最大值
|
V |
minValue()
获取最小值
|
List<List<V>> |
pathList()
获取所有路径列表
从根节点,到叶子节点的路径
|
List<V> |
postOrder()
先序遍历:即根-左-右遍历,不再详述。
|
List<V> |
preOrder()
先序遍历:即根-左-右遍历,不再详述。
|
void |
print()
打印思路
|
boolean |
remove(V data)
情况 1:如果删除的节点没有右孩子,那么就选择它的左孩子来代替原来的节点。
|
int |
size()
返回元素的个数
|
public boolean contains(V data)
contains 在接口中 ISortTree<V extends Comparable<? super V>>data - 元素public void add(V data)
add 在接口中 ISortTree<V extends Comparable<? super V>>data - 元素public boolean remove(V data)
remove 在接口中 ISortTree<V extends Comparable<? super V>>data - 元素public TreeNode<V> getSuccessor(TreeNode<V> delNode)
delNode - 删除元素public int size()
ISortTreesize 在接口中 ISortTree<V extends Comparable<? super V>>public int maxDepth()
ISortTreemaxDepth 在接口中 ISortTree<V extends Comparable<? super V>>public V minValue()
ISortTreeminValue 在接口中 ISortTree<V extends Comparable<? super V>>public V maxValue()
ISortTreemaxValue 在接口中 ISortTree<V extends Comparable<? super V>>public List<V> inOrder()
ISortTreeinOrder 在接口中 ISortTree<V extends Comparable<? super V>>public List<V> preOrder()
ISortTreepreOrder 在接口中 ISortTree<V extends Comparable<? super V>>public List<V> postOrder()
ISortTreepostOrder 在接口中 ISortTree<V extends Comparable<? super V>>public List<V> levelOrder()
ISortTreelevelOrder 在接口中 ISortTree<V extends Comparable<? super V>>public List<List<V>> pathList()
ISortTreepathList 在接口中 ISortTree<V extends Comparable<? super V>>public void print()
print 在接口中 ISortTree<V extends Comparable<? super V>>Copyright © 2020. All rights reserved.