BST Node
A tree is a non-linear linked structure.
We can easily repurpose the Node
class to implement a binary tree.
public class BstOrderedSet<T extends Comparable<T>>
implements OrderedSet<T> {
private Node<T> root;
private static class Node<E> {
E data;
Node<E> left;
Node<E> right;
Node(E data) {
this.data = data;
}
}
// Other operations not shown here.
}
In Node
, the left
reference variable points to the root of the left subtree, i.e.the left child of the node. Likewise, the right
reference variable points to the root of the right subtree, i.e. the right child of the node.