Linked list with multiple parent and child nodes

后端 未结 6 2099
时光说笑
时光说笑 2021-01-06 00:52

I am trying to design a program that takes in data from a file, after which it gives numbering to unique data, linked list also contains parent and child lists.

Data

6条回答
  •  花落未央
    2021-01-06 01:29

    Is it possible to create linked list with nodes with more than one next or more than one previous nodes, if so how would the struct look like?

    Yes it is possible -- the question you must ask yourself is "how do I store an aribitrarily large amount of data?", the brief answer being "you must use an ADT". Recall that an ADT is a mathematical model for a collection of data.

    You can implement it with any ADT, the choice of the specific ADT depends on the operations you plan to use most frequently. For my example, I will use a dynamic array. The structure would be declared as follows (omitting the specific fields for the node):

    struct llnode {
      int item;
      struct llnode *children;
      int length;
      int capacity;
    };
    

    ... where the item is the ASCII code for 'A', 'B', 'C', etc. and children is a pointer to an array of struct llnodes. You can however create a separate structure for a dynamic array to be less messy however it is entirely up to you. The same idea would apply to the parent nodes.

提交回复
热议问题