Is List a linked list?

前端 未结 2 1385
耶瑟儿~
耶瑟儿~ 2021-01-17 13:03

Is System.Collections.Generic.List a type of linked list(not the LinkedList class)?

A linked

相关标签:
2条回答
  • 2021-01-17 13:48

    List<T>, from a... technical perspective, is NOT a type of linked list.

    If you want to have a linked list in C# :

    • either use the built-in LinkedList<T> type (for double-linked lists)
    • or create an implementation of your own (if you want a singly-linked one) - here's an example
    0 讨论(0)
  • 2021-01-17 13:49

    No, List<T> is backed by an array - it's essentially a generic version of ArrayList from .NET 1.0. From the docs:

    The List<T> class is the generic equivalent of the ArrayList class. It implements the IList<T> generic interface using an array whose size is dynamically increased as required.

    Note that due to being backed by an array, its access via indexers is O(1) as opposed to the O(N) for a linked list.

    If you want a linked list, use LinkedList<T>. Note that this is a doubly-linked list. I don't believe .NET exposes a singly-linked list type.

    0 讨论(0)
提交回复
热议问题