Section 6.4 Implementation
Keeping in mind the definitions from the previous section, we can use the following functions to create and manipulate a binary tree:
BinaryTree()
creates a new instance of a binary tree.getRootValue()
returns the object stored in the current node.setRootValue(value)
stores the object in parametervalue
in the current node.getLeftChild()
returns the binary tree corresponding to the left child of the current node.getRightChild()
returns the binary tree corresponding to the right child of the current node.insertLeft(value)
creates a new binary tree and installs it as the left child of the current node.insertRight(value)
creates a new binary tree and installs it as the right child of the current node.
The key decision in implementing a tree is choosing a good internal storage technique. There are two very interesting possibilities, and we will examine both before choosing the one that is more suited to use in Java. We call them array of arrays and nodes and references.
You have attempted of activities on this page.