Java Reference
In-Depth Information
two link instance variables. There are other kinds of trees with different numbers of
link instance variables, but the binary tree is the most common case.
Display 15.39 A Binary Tree
root
40
20
50
null
10
null
30
null
60
null
null
null
null
left subtree
right subtree
1 public class IntTree
2 {
3 public class IntTreeNode
4 {
5 private int data;
6 private IntTreeNode leftLink;
7 private IntTreeNode rightLink;
8 } //End of IntTreeNode inner class
9
private IntTreeNode root;
<The methods and other inner classes are not shown.>
10 }
The instance variable named root serves a purpose similar to that of the instance
variable head in a linked list (Display 15.3). The node whose reference is in the root
instance variable is called the root node . Any node in the tree can be reached from the
root node by following the links.
root node
 
 
Search WWH ::




Custom Search