1

I have a problem about Linked Lists. I already know how to create structures 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?

3
  • 3
    Wouldn't that be a tree? Commented May 10, 2010 at 15:54
  • 1
    You want to create a list of lists? Ok... What is stopping you? You already have the structs defined. Commented May 10, 2010 at 16:00
  • the problem is i can't figure out how to create a lot of linked lists. You know, i before simply create only one list and do the work on it. Will i need a lot of head pointers or etc. now. Can you be more specific? Commented May 10, 2010 at 16:15

1 Answer 1

3

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".

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the comment. Actually i want to put some code to get people's ideas about this issue. This is why i'm waiting :)
Did you make some progress with that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.