19 type(linked_list),
pointer :: next
20 type(list_data) :: data
27 interface assignment(=)
28 module procedure list_assign
30 private :: list_assign
43 subroutine list_assign( list_left, list_right )
44 type(linked_list),
INTENT(OUT) :: list_left
45 type(linked_list),
INTENT(IN) :: list_right
52 stop
'Error: ordinary assignment for lists'
53 list_left%next => null()
54 end subroutine list_assign
69 subroutine list_create( list, data )
70 type(linked_list),
pointer :: list
71 type(list_data),
intent(in) :: data
76 end subroutine list_create
86 subroutine list_destroy( list )
87 type(linked_list),
pointer :: list
89 type(linked_list),
pointer :: current
90 type(linked_list),
pointer :: next
93 do while (
associated(current%next) )
98 end subroutine list_destroy
105 integer function list_count( list )
106 type(linked_list),
pointer :: list
108 type(linked_list),
pointer :: current
109 type(linked_list),
pointer :: next
111 if (
associated(list) )
then
114 do while (
associated(current%next) )
115 current => current%next
116 list_count = list_count + 1
121 end function list_count
129 function list_next( elem ) result(next)
130 type(linked_list),
pointer :: elem
131 type(linked_list),
pointer :: next
135 end function list_next
144 subroutine list_insert( elem, data )
145 type(linked_list),
pointer :: elem
146 type(list_data),
intent(in) :: data
148 type(linked_list),
pointer :: next
152 next%next => elem%next
155 end subroutine list_insert
163 subroutine list_insert_head( list, data )
164 type(linked_list),
pointer :: list
165 type(list_data),
intent(in) :: data
167 type(linked_list),
pointer :: elem
174 end subroutine list_insert_head
183 subroutine list_delete_element( list, elem )
184 type(linked_list),
pointer :: list
185 type(linked_list),
pointer :: elem
187 type(linked_list),
pointer :: current
188 type(linked_list),
pointer :: prev
190 if (
associated(list,elem) )
then
196 do while (
associated(current) )
197 if (
associated(current,elem) )
then
198 prev%next => current%next
199 deallocate( current )
203 current => current%next
211 end subroutine list_delete_element
218 function list_get_data( elem ) result(data)
219 type(linked_list),
pointer :: elem
221 type(list_data) :: data
224 end function list_get_data
232 subroutine list_put_data( elem, data )
233 type(linked_list),
pointer :: elem
234 type(list_data),
intent(in) :: data
237 end subroutine list_put_data