Doubly-linked list/Definition: Difference between revisions
Content added Content deleted
(added Unicon example) |
|||
Line 841: | Line 841: | ||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Tested with g95. |
Tested with g95 and gfortran v. 4.6. |
||
<lang fortran> |
<lang fortran> |
||
module dlist |
module dlist |
||
Line 862: | Line 862: | ||
contains |
contains |
||
! Create a new doubly-linked list |
! Create a new doubly-linked list |
||
type(dll) function new_dll() |
elemental type(dll) function new_dll() |
||
new_dll = dll() |
new_dll = dll(null(),null(),0) |
||
return |
return |
||
end function new_dll |
end function new_dll |
||
! Append an element to the end of the list |
! Append an element to the end of the list |
||
subroutine append(dl2, value) |
elemental subroutine append(dl2, value) |
||
type(dll), intent(inout) :: dl2 |
type(dll), intent(inout) :: dl2 |
||
integer, intent(in) :: value |
integer, intent(in) :: value |
||
type(node) :: element |
|||
type(node), pointer :: np |
type(node), pointer :: np |
||
Line 891: | Line 890: | ||
! Prepend an element to the beginning of the list |
! Prepend an element to the beginning of the list |
||
subroutine prepend(dl2, value) |
elemental subroutine prepend(dl2, value) |
||
type(dll), intent(inout) :: dl2 |
type(dll), intent(inout) :: dl2 |
||
integer, intent(in) :: value |
integer, intent(in) :: value |
||
type(node) :: element |
|||
type(node), pointer :: np |
type(node), pointer :: np |
||
Line 912: | Line 910: | ||
! Insert immediately before the given index |
! Insert immediately before the given index |
||
subroutine insert(dl2, index, value) |
elemental subroutine insert(dl2, index, value) |
||
type(dll), intent(inout) :: dl2 |
type(dll), intent(inout) :: dl2 |
||
integer, intent(in) :: index |
integer, intent(in) :: index |
||
Line 1,022: | Line 1,020: | ||
end subroutine tidy |
end subroutine tidy |
||
subroutine init(dl2, value) |
elemental subroutine init(dl2, value) |
||
type(dll), intent(inout) :: dl2 |
type(dll), intent(inout) :: dl2 |
||
integer, intent(in) :: value |
integer, intent(in) :: value |