Traverse from the beginning of a singly-linked list to the end.



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 NULL 0
 
function alloc_ll_int( n as integer ) as ll_int ptr
    dim as ll_int ptr ret = allocate(sizeof(ll_int))
    ret->n = n
    ret->nxt = NULL
    return ret
end function
 
sub traverse_ll_int( head as ll_int ptr )
    dim as ll_int ptr curr = head
    while curr <> NULL
        print curr->n
        curr = curr->nxt
    wend
end sub
 
dim as ll_int ptr curr, head = alloc_ll_int( 0 ), node
dim as integer i
curr=head
for i = 1 to 50
    'build a list to traverse. This is basically a traversal itself...
    node = alloc_ll_int( i )
    insert_ll_int( curr, node )
    curr = curr->nxt
next i
 
traverse_ll_int( head )