Lists#

class data_structures.lists.base.Node(value: T | None = None, next_node: Self | None = None)[source]#

Bases: Node[T]

Node with a reference to the next node, shared by every linked list.

__init__(value: T | None = None, next_node: Self | None = None) None[source]#
property next: Self | None#

The next node in the list, if any.

class data_structures.lists.singly_linked_list.SinglyLinkedList(value: T | None = None)[source]#

Bases: ILinkedList[T, Node[T]]

Singly linked list that tracks its head node and supports forward iteration. Positions are 0-indexed.

prepend(value: T) None[source]#

Adds a value to the front of the list.

append(value: T) None[source]#

Adds a value to the end of the list.

insert(value: T, pos: int) None[source]#

Inserts a value at the given position.

remove(value: T, all_values: bool = False) None[source]#

Removes the first occurrence of the value, or all occurrences if all_values is set.

reverse() None[source]#

Reverses the list in place.

class data_structures.lists.double_linked_list.Node(value: T | None = None, next_node: Self | None = None, prev_node: Self | None = None)[source]#

Bases: Node[T]

Node in a double linked list, holding a value and the references to the next and previous nodes.

__init__(value: T | None = None, next_node: Self | None = None, prev_node: Self | None = None) None[source]#
property prev: Self | None#

The previous node in the list, if any.

class data_structures.lists.double_linked_list.DoubleLinkedList(value: T | None = None)[source]#

Bases: ILinkedList[T, Node[T]]

Double linked list that tracks its head node and supports forward and backward iteration. Positions are 0-indexed.

prepend(value: T) None[source]#

Adds a value to the front of the list.

append(value: T) None[source]#

Adds a value to the end of the list.

insert(value: T, pos: int) None[source]#

Inserts a value at the given position.

remove(value: T, all_values: bool = False) None[source]#

Removes the first occurrence of the value, or all occurrences if all_values is set.

reverse() None[source]#

Reverses the list in place.