Discussion in 'C' started by ali0482, Sep 1, 2010.
Why is it difficult to store linked list in an array?
What do you mean by difficult?
the difficult is not to store it in an array but to manipulate it.
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.
Separate names with a comma.