Logo

Programming-Idioms

History of Idiom 9 > diff from v9 to v10

Edit summary for version 10 by :

Version 9

2015-09-05, 15:30:44

Version 10

2015-09-13, 17:11:16

Idiom #9 Create a Binary Tree data structure

The structure must be recursive because left child and right child are binary trees too. A node has access to children nodes, but not to its parent.

Idiom #9 Create a Binary Tree data structure

The structure must be recursive because left child and right child are binary trees too. A node has access to children nodes, but not to its parent.

Code
class BinTree<T extends Comparable<T>>{
   T value;
   BinTree<T> left;
   BinTree<T> right;
}
Code
class BinTree<T extends Comparable<T>>{
   T value;
   BinTree<T> left;
   BinTree<T> right;
}
Comments bubble
Note that with this design an empty tree is null, and thus is not an instance of BinTree.