Linked Lists
A linked list is a data structure that is similar to an array in that both can be used for data that is a sequential list of elements.
A linked list is a collection of elements, or nodes. Each node contains a pointer to the next node and thus the nodes need not be adjacent in memory.
Adding a Node
Empty List
; initiate
LD R2, NEW_ITEM
LD R1, LISTHEAD
; insert
STR R2, R0, #0
STR R1, R2, #0
Not Empty List
; R2 is the node to insert
; R1 is the current pointer, R0 is the previous pointer
; initiate
LD R2, NEW_ITEM
LD R1, LISTHEAD
; compare, to sort by NAMEs
LOOP ...
BRp INSERT
BRn MOVE_PTR
BRz LOOP
; move pointer
MOVE_PTR ADD R0, R1, #0
LDR R1, R1, #0
; insert
INSERT STR R2, R0, #0
STR R1, R2, #0