Remove key-value pair from list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(sllist_obj), | intent(inout), | target | :: | this |
List object |
|
| integer, | intent(in) | :: | key |
Key of key-val pair to remove |
pure subroutine sllist_obj_Remove(this,key) !> Remove key-value pair from list. implicit none class(sllist_obj), intent(inout), & target :: this !! List object integer, intent(in) :: key !! Key of key-val pair to remove ! Work variables type(sllist_obj), pointer :: current type(sllist_obj), pointer :: prev if (this%key == key) then ! Removing the head node if (.not.associated(this%child)) then this%key = -1 deallocate(this%val) this%child => null() else this%key = this%child%key deallocate(this%val) allocate(this%val, source = this%child%val) this%child => this%child%child end if else ! Removing other nodes prev => null() current => this do while (associated(current)) if (current%key == key) then prev%child => current%child deallocate(current) return end if prev => current current => current%child end do end if return end subroutine sllist_obj_Remove