Logo

Programming-Idioms

History of Idiom 17 > diff from v27 to v28

Edit summary for version 28 by programming-idioms.org:
New Java implementation by user [programming-idioms.org]

Version 27

2016-05-16, 22:02:27

Version 28

2016-12-04, 21:17:10

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Imports
import java.util.List;
import java.util.ArrayList;
Code
class Tree<K,V> {
  K key;
  V deco;
  List<Tree<K,V>> children = new ArrayList<>();
}
Comments bubble
Then you will want to add constructors, getters, setters.
Demo URL
http://ideone.com/g8aQaj