IntTree Contract

The IntTree class describes immutable binary trees of integers. An integer binary tree is either the empty tree (a leaf) or a (non-empty) tree node with a value component that is an integer and left and right components that are integer binary trees. The trees are immutable in the sense that the value, left, and right components of a tree node cannot be changed after the tree node has been created (via the node() method).

There are no public constructor or instance methods for integer binary trees; they are created and manipulated by the following class methods:

Class Methods

public static IntTree leaf()
Returns an empty integer binary tree.

public static IntTree node (int n, IntTree L, IntTree R)
Returns a new integer binary tree node whose value is n, whose left subtree is L, and whose right subtree is R.

public static boolean isLeaf (IntTree T)
Returns true if T is a leaf and false if T is an integer binary tree node.

public static int value (IntTree T)
Returns the integer that is the value component of the integer binary tree node T. Signals an exception if T is a leaf.

public static IntTree left (IntTree T)
Returns the integer binary tree that is the left component of the integer binary tree node T. Signals an exception if T is a leaf.

public static IntTree right (IntTree T)
Returns the integer binary tree that is the right component of the integer binary tree node T. Signals an exception if T is a leaf.