Thread: Creating a list with elements other lists (same struct)

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    3

    Creating a list with elements other lists (same struct)

    Lets say i have 3 lists : list1,list2,list3.
    Their struct of each element of those lists :
    Code:
    struct node {
        char value[20];
        struct node * next ;    
        int occurs;
    };


    Code:
    typedefstruct node Node;
    typedefNode*List;

    but i dont think it matters.
    I want to create a new list but every element of it has to be each of those 3 lists.My new struct for this matter is that(its correct):
    Code:
    typedefstruct listoflists{
        Listlist;
        struct listoflists*next;
    }Nested;

    My new function to make the list :
    Code:
    void createlistoflists(Nested**LIST,List list1,List list2,List list3){
         if(*LIST==NULL){
             *LIST=listab;
         }
         else

    So im not sure if the begging is even correct but how will i fill it(and correct) in order to achieve the list of lists?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,681
    So what does the result look like?
    Code:
    If you have
    list1 -> a -> b -> c
    list2 -> d -> e -> f
    list3 -> g -> h -> i
    
    Is your combines list like this
    combined -> a -> b -> -> d -> e -> f -> g -> h -> i
    
    Or like this
    combined
        |
        V
    	list1 -> a -> b -> c
        |
        V
    	list2 -> d -> e -> f
        |
        V
    	list3 -> g -> h -> i
    
    Or something else?
    Are you making copies of list1,2,3 or removing the elements to put them in the new list?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    3
    The 2nd scenario for how the list should be. All it asks is a list with elements the lists 123,otherwise it would say list with elements the elements of lists 123 right?Now for the 2nd question i think it should be copies because it would say new lists 123.Its actually not clear
    Also look at the struct i set for the listoflists(its how it has to be done).
    And it has to be done in one function.
    Last edited by lltocl; 06-16-2018 at 05:58 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,681
    Well this would be a better prototype, which you call 3 times.

    Code:
    Nested *createlistoflists(Nested*lol,List list);
    Which you call as
    Code:
    Nested *lol = NULL;
    lol = createlistoflists(lol,list1);
    lol = createlistoflists(lol,list2);
    lol = createlistoflists(lol,list3);
    You can rename this particular function, then make your given prototype make those three calls as above.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Don't Understand Outputting Linked Lists Elements
    By NM Greg in forum C++ Programming
    Replies: 4
    Last Post: 08-20-2017, 01:35 AM
  2. Replies: 3
    Last Post: 10-23-2011, 09:18 PM
  3. Need soem suggestions on my Binary Search Tree Implementation
    By indigo0086 in forum C++ Programming
    Replies: 14
    Last Post: 10-10-2007, 10:20 AM
  4. Tree traversal eating/creating elements?
    By patricio2626 in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2006, 07:37 AM
  5. Replies: 22
    Last Post: 10-22-2005, 08:42 AM

Tags for this Thread