Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.

See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


struct SLinkedNode(T) {
    T data;
    typeof(this)* next;
}
 
void insertAfter(T)(SLinkedNode!T* listNode, SLinkedNode!T* newNode) {
    newNode.next = listNode.next;
    listNode.next = newNode;
}
 
void main() {
    alias N = SLinkedNode!char;
 
    auto lh = new N('A', new N('B'));
    auto c = new N('C');
 
    // Inserts C after A, creating the (A C B) list:
    insertAfter(lh, c);
 
    // The GC will collect the memory.
}