Logo

Programming-Idioms

History of Idiom 17 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-09-03, 17:11:33

Version 12

2015-09-13, 17:55:32

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 his 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 his parent.

Code
type Tree struct {
	Key keyType
	Deco valueType
	Children []*Tree
}
Code
type Tree struct {
	Key keyType
	Deco valueType
	Children []*Tree
}
Comments bubble
keyType should be easily comparable.
valueType is a type of value associated with current node, distinct from the key.
Children is a slice of pointers.
Comments bubble
keyType should be easily comparable.
valueType is a type of value associated with current node, distinct from the key.
Children is a slice of pointers.


Note that in Go you can call methods of pointer type *Tree even on a nil receiver (an empty tree).