38 integer,
public :: size = 0
39 class(list_node_t),
pointer :: first_node => null()
40 class(list_node_t),
pointer :: last_node => null()
48 generic ::
assignment(=) => copy
61 class(list_node_t),
pointer :: next_node => null()
123 class(linked_list_t),
intent(inout) :: this
124 class(*),
target ::
value
125 logical,
intent(in) :: clone
127 class(list_node_t),
pointer :: new_node
129 if (.not.
associated(this%first_node))
then
130 this%first_node =>
list_node_t(
value, this%first_node, clone)
131 this%last_node => this%first_node
134 call this%last_node%set_next(new_node)
135 this%last_node => new_node
137 this%size = this%size + 1
145 class(*),
target ::
value
147 call this%add_node(
value, clone=.false.)
155 class(*),
target ::
value
157 call this%add_node(
value, clone=.
true.)
165 class(*),
target ::
value
167 class(
list_node_t),
pointer :: previous, current, next
171 next => this%first_node
172 do while (
associated(next))
176 if (current%is_equal(
value))
then
177 if (
associated(next) .and. .not.
associated(previous))
then
179 this%first_node => next
180 else if (.not.
associated(next) .and.
associated(previous))
then
182 call previous%set_next(null())
183 this%last_node => previous
184 else if (.not.
associated(next) .and. .not.
associated(previous))
then
186 nullify(this%first_node)
187 nullify(this%last_node)
190 call previous%set_next(next)
193 this%size = this%size - 1
214 current => this%first_node
215 do while (
associated(current))
216 next => current%next()
220 nullify(this%first_node)
221 nullify(this%last_node)
233 current => rhs%first_node
234 do while (
associated(current))
235 if (.not.
associated(lhs%first_node))
then
236 lhs%first_node => current%copy(lhs%first_node)
237 lhs%last_node => lhs%first_node
239 new_node => current%copy(lhs%last_node%next())
240 call lhs%last_node%set_next(new_node)
241 lhs%last_node => new_node
243 current => current%next()
252 class(*),
target :: value
256 current => this%first_node
260 current => current%next()
270 this%next_node => list%first_node
285 class(*),
pointer :: value
287 value => this%next_node%get()
288 this%next_node => this%next_node%next()
297 class(
list_t),
intent(inout) :: this
298 class(*),
target :: value
300 call this%add_ptr(
value)
307 class(*),
pointer :: value
309 value => this%get_next_ptr()
318 integer,
target :: value
320 call this%add_copy(
value)
329 select type (ptr => this%get_next_ptr())
This module implements fully polymorphic linked lists, and some specializations thereof.
subroutine linked_list_add_node_ptr(this, value)
add data by pointer to the list
subroutine linked_list_add_node_copy(this, value)
add data by copying to the list
subroutine linked_list_iterator_start(this, list)
subroutine integer_list_add_node(this, value)
subroutine list_add_node(this, value)
logical function linked_list_iterator_has_next(this)
subroutine linked_list_add_node(this, value, clone)
add a node to the linked list
class(*) function, pointer list_iterator_get_next(this)
subroutine linked_list_copy(lhs, rhs)
class(*) function, pointer linked_list_iterator_get_next_ptr(this)
subroutine linked_list_finalize(this)
subroutine linked_list_empty(this)
logical function linked_list_has(this, value)
integer function integer_iterator_get_next(this)
subroutine linked_list_delete_node(this, value)
delete a node from the list
This module implements a node of a polymorphic linked list.
This class implements a linked list of integer values.
This class implements an iterator for the polymorphic linked list.
This class implements a linked list of unlimited polymorphic values.
This class implements a linked list of unlimited polymorphic values.
class for a node in a polymorphic linked list