Jump to content

Singly-linked list/Traversal: Difference between revisions

no edit summary
No edit summary
Line 257:
Testing code:
A ' emit walk <em>ABC ok</em>
 
=={{header|Fortran}}==
Fortran 95. See [[Singly-Linked List (element)#Fortran|Singly-Linked List (element) in Fortran]].
<lang fortran>subroutine traversal(list,proc)
type(node), target :: list
type(node), pointer :: current
interface
subroutine proc(node)
real, intent(in) :: node
end subroutine proc
end interface
current => list
do while ( associated(current) )
call proc(current%data)
current => current%next
end do
end subroutine traversal</lang>
Print data from all nodes of a singly-linked list:
<lang fortran>subroutine printNode(data)
real, intent(in) :: data
write (*,*) data
end subroutine
 
subroutine printAll(list)
type(node), intent(in) :: list
call traversal(list,printNode)
end subroutine printAll</lang>
 
=={{header|Go}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.