Java Reference
In-Depth Information
F
IGURE
25.2
The animation tool enables you to insert, delete, and search elements.
25.2.1 Representing Binary Search Trees
A binary tree can be represented using a set of linked nodes. Each node contains a value and
two links named
left
and
right
that reference the left child and right child, respectively, as
shown in FigureĀ 25.3.
root
60
55
100
45
57
67
107
F
IGURE
25.3
A binary tree can be represented using a set of linked nodes.
A node can be defined as a class, as follows:
class
TreeNode<E> {
protected
E element;
protected
TreeNode<E> left;
protected
TreeNode<E> right;
public
TreeNode(E e) {
element = e;
}
}
Search WWH ::
Custom Search