linked list in an array

ali0482's Avatar
Light Poster
Why is it difficult to store linked list in an array?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
What do you mean by difficult?
virxen's Avatar, Join Date: Nov 2009
Pro contributor
the difficult is not to store it in an array but to manipulate it.
xpi0t0s's Avatar, Join Date: Aug 2004
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.