Yes, therefore it is called the directed graph. And there are about a thousand ways to implement it. The โcorrectโ method depends entirely on how you use it, which you did not describe. Since you seem to limit this to linked lists or doubly linked lists, I just use only doubly linked lists.
Forward declare your data types
typedef struct ItemInfo_s ItemInfo; typedef struct DoubleLinkedListNode_s DoubleLinkedListNode;
Create a ListNode, as you always have:
struct DoubleLinkedListNode_s { DoubleLinkedListNode *next; DoubleLinkedListNode *prev; ItemInfo *data; };
Then create your ItemInfo:
struct ItemInfo_s { DoubleLinkedListNode *children; DoubleLinkedListNode *parents; ... };
In addition, to intelligently create a list of all created nodes:
DoubleLinkedListNode *items;
Now I wonโt write all the related list management functions, but Iโm sure you can understand it. By convention, I will write (B) as node pointing to element B (node.data = & B). I will also indicate any two nodes connected together with '=' and a '-' as an unbound (zero) node connection. I will write a chain of elements [- (1) = (2) = (3) -], and pointers to pointers to a chain of elements will always point to the first node in the chain ((1) in this example). Your schedule will look like this:
items = [ -(A)=(B)=(C)=(E)=(F)=(G)=(I)=(J)=(K)- ] A.children = [ -(B)=(C)- ] A.parents = [] B.children = [ -(E)- ] B.parents = [ -(A)- ] C.children = [ -(E)=(G)- ] C.parents = [ -(A)- ] E.children = [ -(I)=(F)- ] E.parents = [ -(B)=(C)- ] F.children = [ -(J)- ] F.parents = [ -(E)- ] G.children = [ -(K)- ] G.parents = [ -(C)- ] I.children = [] I.parents = [ -(E)- ] J.children = [] J.parents = [ -(F)- ] K.children = [] K.parents = [ -(G)- ]
In total, these are 9 ItemInfos and 27 DoubleLinkedListNodes. I hardly think that I will ever put this into practice, but it is implemented using only two linked lists. This may make managing the list easier to make doubly linked rings (connecting the head and tail of the list together), but it's harder to show in text form. :)