Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C#

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.

using System.Collections.Generic
class Node<T>
{
 T value;
 List<Node<T>> childNodes;
}

The Children can be stored in an Array or List, depending on how you want to implement it.
typedef struct node_s
{
    int value;
    struct node_s *nextSibling;
    struct node_s *firstChild;
} node_t;

New implementation...