Click to See Complete Forum and Search --> : Is it possible to create an Indexing on Linked List


rsodimbakam
September 17th, 2008, 11:40 PM
Hi,
When comparing Arrays with LinkedList, i observed that, we can doindexing on Arrays which is not possible in case of LinkedList as it does not use the Contigious memory for allocation, so is it possible to overcome this limitation, i mean is it possible to create contigious memroy allocation for linkedlist ?

Pls clarify me on this.

Thanks
Kiran

cilu
September 18th, 2008, 12:55 AM
No. That would be an array. Linked lists have advantages and disadvantages. What are you trying to do?

rsodimbakam
September 18th, 2008, 03:37 AM
Hi, i have found that we can use vector present in C++ STL which could help in indexing the linked list.

Yves M
September 18th, 2008, 06:44 AM
It's possible, but probably not useful. You want to choose your container based on the ways you need to access it. If you need random access by an index, you probably want an array anyways. If you need insertion and deletion of elements at any position very quickly then a linked list is better. Constructing an index of a linked list gives you the disadvantages of having long insertion/deletion time so you might just as well use a regular array (or vector) in the first place.