"DoublyLinkedList" (Data Structure)


represents a doubly linked list where the elements are general expressions.


  • A doubly linked list is useful for efficiently adding and removing elements from the first and last positions:
  • CreateDataStructure["DoublyLinkedList"]create a new empty "DoublyLinkedList"
    CreateDataStructure["DoublyLinkedList",elems]create a new "DoublyLinkedList" containing elems
    Typed[x,"DoublyLinkedList"]give x the type "DoublyLinkedList"
  • For a data structure of type "DoublyLinkedList", the following operations can be used:
  • ds["Append",x]append x to dstime: O(1)
    ds["Copy"]return a copy of dstime: O(n)
    ds["DropAll"]drop all the elements from dstime: O(n)
    ds["DropFirst"]drop the first element of dstime: O(1)
    ds["DropLast"]drop the last element of dstime: O(1)
    ds["Elements"]return a list of the elements of dstime: O(n)
    ds["EmptyQ"]True, if ds has no elementstime: O(1)
    ds["Fold",fun,init]apply fun to the elements of ds, starting with init, accumulating a resulttime: O(n)
    ds["JoinBack",elems]join elems to the back of dstime: O(nelems)
    ds["JoinFront",elems]join elems to the front of dstime: O(nelems)
    ds["Length"]number of elements stored in dstime: O(1)
    ds["Part",i]give the i^(th) part of dstime: O(n)
    ds["Prepend",x]prepend x to dstime: O(1)
    ds["SetPart",i,elem]update the i^(th) part of dstime: O(n)
    ds["SwapPart",i,j]swap the i^(th) and j^(th) parts of dstime: O(n)
    ds["Visualization"]return a visualization of dstime: O(n)
  • The following functions are also supported:
  • dsi===dsjTrue, if dsi equals dsj
    ds["Part",i]=valset i^(th) element of ds to val
    FullForm[ds]full form of ds
    Information[ds]information about ds
    InputForm[ds]input form of ds
    Normal[ds]convert ds to a normal expression


open allclose all

Basic Examples  (2)

A new "DoublyLinkedList" can be created with CreateDataStructure:

Elements can be appended:

Elements can be prepended:

Return the length:

Extract the first element:

Change an element:

The element has updated:

Return an expression version of ds:

Drop the last element:

It is fast to append:

A visualization of the data structure can be generated:

Sum all the elements:

Scope  (1)

Information  (1)

A new "DoublyLinkedList" can be created with CreateDataStructure:

Information about the data structure ds: