Remove an item from the list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| type(node), | pointer | :: | p |
the item to remove |
subroutine remove_by_pointer(me,p) implicit none class(list),intent(inout) :: me type(node),pointer :: p !! the item to remove logical :: has_next, has_previous if (associated(p)) then call p%destroy() ! destroy the data has_next = associated(p%next) has_previous = associated(p%previous) if (has_next .and. has_previous) then !neither first nor last in a list p%previous%next => p%next p%next%previous => p%previous elseif (has_next .and. .not. has_previous) then !first one in a list me%head => p%next me%head%previous => null() elseif (has_previous .and. .not. has_next) then !last one in a list me%tail => p%previous me%tail%next => null() elseif (.not. has_previous .and. .not. has_next) then !only one in the list me%head => null() me%tail => null() end if deallocate(p) nullify(p) me%count = me%count - 1 end if end subroutine remove_by_pointer