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
#define FIL    1
#define DATO   2
#define LPREV  3
#define LNEXT  4
 
Dim Shared As Integer countNodes, Nodes
countNodes = 0
Nodes = 10
 
Dim Shared As Integer list(Nodes, 4)
list(0, LNEXT) = 1
 
Function searchNode(node As Integer) As Integer
    Dim As Integer Node11
 
    For i As Integer = 0 To node-1
        Node11 = list(Node11, LNEXT)
    Next i
    Return Node11
End Function
 
Sub insertNode(node As Integer, newNode As Integer)
    Dim As Integer Node11, i
 
    If countNodes = 0 Then node = 2
 
    For i = 1 To Nodes
        If Not list(i, FIL) Then Exit For
    Next
    list(i, FIL) = True
    list(i, DATO) = newNode    
 
    Node11 = searchNode(node)
 
    list(i, LPREV) = list(Node11, LPREV) 
    list(list(i, LPREV), LNEXT) = i
    If i <> Node11 Then list(i, LNEXT) = Node11 : list(Node11, LPREV) = i
 
    countNodes += 1
    If countNodes = Nodes Then Nodes += 10 : Redim list(Nodes, 4)
End Sub
 
Sub removeNode(n As Integer)
    Dim As Integer Node11 = searchNode(n)
    list(list(Node11, LPREV), LNEXT) = list(Node11, LNEXT)
    list(list(Node11, LNEXT), LPREV) = list(Node11, LPREV)
    list(Node11, LNEXT) = 0 
    list(Node11, LPREV) = 0
    list(Node11, FIL) = False
    countNodes -= 1
End Sub
 
Sub printNode(node As Integer)
    Dim As Integer Node11 = searchNode(node)
    Print list(Node11, DATO);
    Print
End Sub
 
Sub traverseList()
    For i As Integer = 1 To countNodes
        printNode(i)
    Next i
End Sub
 
insertNode(1, 1000)
insertNode(2, 2000)
insertNode(2, 3000)
 
traverseList()
 
removeNode(2)
 
Print
traverseList()
Sleep