fn SinglyLinkedList(comptime T: type) type

A singly-linked list is headed by a single forward pointer. The elements are singly linked for minimum space and pointer manipulation overhead at the expense of O(n) removal for arbitrary elements. New elements can be added to the list after an existing element or at the head of the list. A singly-linked list may only be traversed in the forward direction. Singly-linked lists are ideal for applications with large datasets and few or no removals or for implementing a LIFO queue.

Parameters

T: type,

Fields

first: ?*Node = null,

Types

Functions

fn len(list: Self) usize

Iterate over all nodes, returning the count. This operation is O(N).

fn popFirst(list: *Self) ?*Node

Remove and return the first node in the list.

Remove and return the first node in the list.

Returns: A pointer to the first node in the list.

fn prepend(list: *Self, new_node: *Node) void

Insert a new node at the head.

Insert a new node at the head.

Arguments: new_node: Pointer to the new node to insert.

fn remove(list: *Self, node: *Node) void

Remove a node from the list.

Remove a node from the list.

Arguments: node: Pointer to the node to be removed.