views:

676

answers:

4

I was looking in Generics.Collections and noticed there was no linked list. Sure they are simple to make, but I thought it was odd there was not one (or I just missed it). Are linked lists just outdated when compared to new modern data structures, or is there a need for a general generic linked list? Does anyone know of one?

+2  A: 

In the old days, almost any piece of serious software contained linked lists or trees.

I haven't used linked lists alot, but trees are another story.

With the introduction of dynamic arrays, there is not that much need for linked lists. But I can imagine that you want to use it if your datastructure is changed often (add + delete).

You can easily create a generic linked list yourself, using a container class and records for the elements.

Gamecat
+1  A: 

I don't know of any generic, linked list in the existing Delphi RTL.

They are still very useful as a data structure, however. Especially if you include variants on a linked list such as a b-tree or a binary tree. Unlike a regular list, a linked list can be expanded, edited, or modified without moving data in memory. They are very easy to version, and work well in purely functional code which does not allow mutating existing data. So it is still a very useful data structure.

Craig Stuntz
+7  A: 

Do you know the DeHL?

I think the TLinkedList<T> class inside of DeHL.Collections.LinkedList.pas is exactly what you are looking for.

ulrichb
A: 

Isn't that what tStringList is for?

(ducking)

Actually, any generic tList works fine as a linked list, and supplies most of the functionality needed. The ancient technique passed down from our ancestors of storing a pointer to memory in each record, and navigating to that has been easily replaced by dynamic arrays and doing things...more generically.

skamradt
When inserting to a TList it requires a memory move of everything after it in the array. A Linked list just requires changing a pointer.
Jim McKeeth
True, it would be much more efficient for large lists and they really aren't that difficult to write. ulrichb has the best answer, the implementation there is just what you asked for.
skamradt