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:
    http://www.nrzee.com/asp-.net/
    Why is it difficult to store linked list in an array?
     
  2. shabbir

    shabbir Administrator Staff Member

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

    virxen Active Member

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

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    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

  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