Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.

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
// Rosetta Code problem: http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion & removal & traverse
// by Galileo, 02/2022
 
FIL = 1 : DATO = 2 : LPREV = 3 : LNEXT = 4
countNodes = 0 : Nodes = 10
 
dim list(Nodes, 4)
 
list(0, LNEXT) = 1
 
 
sub searchNode(node)
    local i, Node
 
    for i = 0 to node-1
        Node = list(Node, LNEXT)
    next
    return Node
end sub
 
sub insertNode(node, newNode)
    local Node, i
 
    if not countNodes node = 2
 
    for i = 1 to Nodes
        if not list(i, FIL) break
    next
    list(i, FIL) = true
    list(i, DATO) = newNode    
 
    Node = searchNode(node)
 
    list(i, LPREV) = list(Node, LPREV) : list(list(i, LPREV), LNEXT) = i
    if i <> Node list(i, LNEXT) = Node : list(Node, LPREV) = i
 
    countNodes = countNodes + 1
    if countNodes = Nodes then Nodes = Nodes + 10 : redim list(Nodes, 4) : end if
end sub
 
 
sub removeNode(n)
    local Node
 
    Node = searchNode(n)
    list(list(Node, LPREV), LNEXT) = list(Node, LNEXT)
    list(list(Node, LNEXT), LPREV) = list(Node, LPREV)
    list(Node, LNEXT) = 0 : list(Node, LPREV) = 0
    list(Node, FIL) = false
    countNodes = countNodes - 1
end sub
 
 
sub printNode(node)
    local Node
 
    Node = searchNode(node)
    print list(Node, DATO);
    print
end sub
 
 
sub traverseList()
    local i
 
    for i = 1 to countNodes
        printNode(i)
    next
end sub
 
 
insertNode(1, 1000)
insertNode(2, 2000)
insertNode(2, 3000)
 
traverseList()
 
removeNode(2)
 
print
traverseList()