Logo

Programming-Idioms

  • Dart
  • Erlang

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 its children nodes, but not to its parent.

-record( node,{
	value         :: any(),
	children = [] :: [node#{}]
}).
class Node<T> {
  final T value;
  final List<Node<T>> children;
  Node(this.value, this.children);
}
  
typedef struct node_s
{
    int value;
    struct node_s *nextSibling;
    struct node_s *firstChild;
} node_t;

New implementation...