| title | linked lists |
|---|
[TOC]
The stdlib_linked_list module defines a class and its interface to handle linked lists that
store any type of data. The list may contain data of the same type or of various types.
Linked lists are variables of the type linked_list_type. The type provides all the methods
required for storing and retrieving data.
Return the number of data items in the list.
number = [[stdlib_linked_list(module):list%size]] ()
Experimental
Pure function.
None
The result is an integer scalar, equal to the number of items currently contained in the list.
{!example/linked_list/example_size.f90!}Remove all items from the list
call [[stdlib_linked_list(module):list%clear]]
Experimental
Subroutine.
None
{!example/linked_list/example_clear.f90!}Get the data item at a given position (node) in the list
item = [[stdlib_linked_list(module):list%get(interface)]] (node_index)
Experimental
Function.
node_index: Shall be a scalar integer equal to the position in the list for the new item. This argument isintent(in).
The data item (of type class(*)) that is stored at the given position.
Notes:
- If the index is 0 or less, the first item in the list is returned.
- If the index is larger than the number of items, the last item in the list is returned.
{!example/linked_list/example_get.f90!}Insert a new item at a given position (node) in the list
call [[stdlib_linked_list(module):list%insert(interface)]] (item, node_index)
Experimental
Subroutine.
item: Data item to be stored (any type). This argument isintent(in).node_index: Shall be an integer scalar equal to the position in the list for the new item. This argument isintent(in).
The list is extended with the new data item at the given position.
Notes:
- If the index is 0 or less, the item is stored at the first position.
- If the index is larger than the number of items, it will be appended to the end of the list.
{!example/linked_list/example_insert.f90!}Replace an existing data by a new item at a given position (node) in the list
call [[stdlib_linked_list(module):list%insert(interface)]] (new_item, node_index)
Experimental
Subroutine.
new_item: The new data item to be stored (any type). This argument isintent(in).node_index: Shall be an integer scalar equal to the position in the list for the item to be replaced. This argument isintent(in).
The new data item is stored and the existing one removed.
Notes:
- If the index is 0 or less, or it is larger than the number of items, nothing is done.
{!example/linked_list/example_replace.f90!}Remove an items at a given position (node) in the list
call [[stdlib_linked_list(module):list%remove(interface)]] (node_index)
Experimental
Subroutine.
node_index: Shall be an integer scalar equal to the position in the list for the item to be removed. This argument isintent(in).
The indicated item has been removed from the list.
Notes:
- If the index is 0 or less or the index is larger than the number of items, nothing is done.
{!example/linked_list/example_remove.f90!}Append a new item to the end of the list
call [[stdlib_linked_list(module):list%push(interface)]] (item)
Experimental
Subroutine.
item: Data item to be stored (any type). This argument isintent(in).
The list is extended with the new data item at the tail.
{!example/linked_list/example_push.f90!}Remove the last item in the list
call [[stdlib_linked_list(module):list%pop(interface)]]
Experimental
Subroutine.
None
The list item in the list is removed.
{!example/linked_list/example_pop.f90!}Reconstruct the list in reverse order
call [[stdlib_linked_list(module):list%reverse(interface)]]
Experimental
Subroutine.
None
The list now contains the items in reverse order.
{!example/linked_list/example_reverse.f90!}Concatenate a list to another list
call [[stdlib_linked_list(module):list%concat(interface)]] (list_to_concat)
Experimental
Subroutine.
list_to_concat: list whose data items are to be appended to the givenlinked_list_typederived type. this argument isintent(in).
The given list is extended with the data items in the second list. The second list remains intact.
{!example/linked_list/example_concat.f90!}Absorb a list into another list
call [[stdlib_linked_list(module):list%absorb(interface)]] (list_to_absorb)
Experimental
Subroutine.
list_to_absorb: list whose data items will be appended to the givenlinked_list_typederived type. this argument isintent(inout).
The given list is extended with the data items in the second list. The second list is emptied.
{!example/linked_list/example_absorb.f90!}Return a sublist of a list
sublist = [[stdlib_linked_list(module):list%slice(interface)]] (start, end)
Experimental
Subroutine.
start: Shall be an integer scalar equal to the first item to store in the sublist. this argument isintent(in).end: Shall be an integer scalar equal to the last item to store in the sublist. this argument isintent(in).
Sublist consisting of the indicated data items. Note that the items themselves are copied from the original list, so that the two lists are independent.
{!example/linked_list/example_slice.f90!}Remove a sublist from a list, based on a start and end index.
call [[stdlib_linked_list(module):list%splice(interface)]] (start, end)
Experimental
Subroutine.
start: Shall be an integer scalar equal to the first item to be removed from the list. this argument isintent(in).end: Shall be an integer scalar equal to the last item to be removed from the list. this argument isintent(in).
The data items in the given range are removed from the list.
{!example/linked_list/example_splice.f90!}