merge linked list

Discussion in 'C' started by rakoczimrks, Sep 12, 2011.

  1. rakoczimrks

    rakoczimrks New Member

    Joined:
    Jul 11, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    I need some help, with the next exercise: I have two simple linked list A and B and i have to create a new one without duplicating the elements, where
    C1=A1 -> C2=B1->C3=A2->C4=B2->C5=A3->C6=B3 ... and so on.
    I'm still thinking how to relink the elements :thinking:
     
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    0
    Code:
    int i;
    int size = A.size(); // given that A and B have equal size
    
    for (i = 0; i < size; i++)
    {
        C.push_back(A.at(i));
        C.push_back(B.at(i));
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice