Linked lists: ordered lists, in which each element has a reference to the next element.
Most operations on linked lists take time proportional to the length of the list, because each element must be traversed to find the next element.
List α is isomorphic to Array α, but they are useful for different things:
-
List αis easier for reasoning, andArray αis modeled as a wrapper aroundList α. -
List αworks well as a persistent data structure, when many copies of the tail are shared. When the value is not shared,Array αwill have better performance because it can do destructive updates.
Constructors
List.nil.{u} {α : Type u} : List α
The empty list, usually written [].
Conventions for notations in identifiers:
-
The recommended spelling of
[]in identifiers isnil.
List.cons.{u} {α : Type u} (head : α) (tail : List α) : List α