开发者

Multiple Linked List in C

I have a problem about Linked Lists. I already know how to create structur开发者_如何学运维es and linked list. But now I have to create arbitrary number of linked list which are also be kept in another structure. Which means :

struct list{int x, struct list *next; };
struct parent{int x, struct list  *head, struct parent *next;}   

And after lists are created when i enter this input for example "123134" linked list should look like :

1 -> 2 -> 3 -> 4

And for example 1 will contain 2->3 list inside of it, 3 will contain 1->4 list inside of it.

I need a starting point and a spark from you. So how can i do this?


Draw your list diagram, which often helps.

Start
 |
list1 -> node1 -> node2
 |
list2 -> node_a -> node_b -> node_c
 |
list3 {empty}
 |
list4 -> node_1A

Given a diagram like the above, the lists have two links, one to their own nodes, another to another list. Some objects may need more than one link field.

In your case, draw a diagram. Try inserting a new item. Write down the steps you take (and draw).

If you supply more details in your question, more people will assist.

For an example of a list with nodes containing many lists, see a BTree data structure. Each node contains an array of links to other "subtrees".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜