lstinsert0
lstinsert0 is a naming convention used in some programming libraries to describe the operation of inserting an element at the head of a list, i.e., at index 0. The exact implementation and side effects depend on whether the list is immutable or mutable, and on the underlying data structure (such as a linked list versus a dynamic array).
In immutable-list contexts, lstinsert0(element, list) returns a new list with the element prepended to the front,
Common signatures and interpretations vary by language:
- Lisp/Scheme: (lstinsert0 element lst) typically results in (cons element lst).
- Python: lstinsert0 = lambda elem, lst: [elem] + lst, producing a new list with elem at the front.
- JavaScript: function lstinsert0(elem, lst) { return [elem].concat(lst); }.
- C for a singly linked list: a function that allocates a new node with data = elem and
- Haskell: element : list, where the colon operator prepends an element.
Complexity and implications: for linked-list implementations, inserting at the head is O(1). For array-backed lists that
See also: prepend, cons, push_front, and zero-based indexing.