linked list in an array

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