In this structure,
Code:
struct node {
/* Vertical links */
struct node *parent;
struct node *child;
/* Horizontal links */
struct node *prev;
struct node *next;
/* Node contents can be anything you need: */
size_t size;
char data[];
};
each node contains data, and there is just that one structure type. I don't normally use handles. Now, consider this structure:
Code:
A0─A1─A2─A3
│ │
│ D0─D1─D2
│
B0─B1─B2
│
C0─C1─C2─C3─C4
You can reach every node from any node, starting with just the node pointer, without extra structure traversals. As long as you do not form any loops, this works fine, and is simple to implement.
I think I did mention that this is more like a directory tree than a 2D array or a list of lists. (In a directory tree, each horizontal sibling would have the same pointer to their parent, because that makes traversals much simpler. So,
B0..
B2 would connect to
A1,
D0..
D2 to
A2, and
C0..
C4 to
B2.)
If you don't need the ability to describe this complexity, there are simpler/better structures one can use. But the above structure does need all four pointers in each node (or more than one type of node), if you want to easily traverse between nodes in any direction.