Logo

Programming-Idioms

History of Idiom 9 > diff from v48 to v49

Edit summary for version 49 by El Gallo:
[Go] This feature of nil pointers is not needed to implement Binary Trees and therefore confusing to include

Version 48

2020-08-16, 19:55:35

Version 49

2020-08-16, 19:58:08

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.

Variables
left,right
Variables
left,right
Code
type BinTree struct {
	Value valueType
	Left *BinTree
	Right *BinTree
}
Code
type BinTree struct {
	Value valueType
	Left *BinTree
	Right *BinTree
}
Comments bubble
valueType is a type of value associated with current node, distinct from the key.

Note that in Go you can call methods of pointer type *BinTree even on a nil receiver (an empty tree).
Comments bubble
valueType is a type of value associated with current node, distinct from the key.
Demo URL
http://play.golang.org/p/MK3qoaVPol
Demo URL
http://play.golang.org/p/MK3qoaVPol