Generic Linked List for Delphi 2009

时光总嘲笑我的痴心妄想 提交于 2019-12-04 03:43:49

问题


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?


回答1:


Do you know the DeHL?

I think the TLinkedList<T> from the DeHL.Collections.LinkedList.pas unit is exactly what you are looking for.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/984916/generic-linked-list-for-delphi-2009

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!