Singly-linked list/Traversal: Difference between revisions

add FreeBASIC
(→‎{{header|Raku}}: Fix up internal link)
(add FreeBASIC)
Line 825:
call traversal(list,printNode)
end subroutine printAll</lang>
 
=={{header|FreeBASIC}}==
Requires the type definition and node insertion routine [[Singly-linked_list/Element_definition#FreeBASIC|here]] and [[Singly-linked_list/Element_insertion#FreeBASIC|here]] respectively. Also includes a routine for allocating space for a node.
 
<lang freebasic>#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 )</lang>
 
=={{header|Go}}==
781

edits