1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

linked list in an array

Discussion in 'C' started by ali0482, Sep 1, 2010.

  1. ali0482

    ali0482 New Member

    Joined:
    Aug 10, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    Why is it difficult to store linked list in an array?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    What do you mean by difficult?
     
  3. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    the difficult is not to store it in an array but to manipulate it.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    If you want to insert an item into the middle of the list, it's easy with a linked list cos you just redirect a couple of pointers. With an array you would have to move everything up a notch to create the free space. Also arrays tend to have a fixed size determined at compile time, whereas the size of a linked lists is determined at runtime.

    But it's not difficult to store a linked list in an array; just loop over the list and copy the elements across one by one.
     

Share This Page