It really is just a solution to implement. Although the array is likely to be a pretty useless data structure if you can't search for items by index, adding index search to the implementation of a linked list does no harm (well, if users don't accept it quickly - see below), and sometimes it come in handy.
Each item can be assigned a number as follows:
0 1 2 3 4
Head (Element0) -> Element1 -> Element2 -> Element3 -> Element4 -> NULL
From here it is trivial to write a function that returns an element at any given index.
Please note that index search on linked lists will be slow - if you want, let them say that the item is in the middle, you will need to work through half the list to get there.
source
share