LinkedList#
- class LinkedList(linked_list_type='singly')#
- Bases: - Container- __init__(linked_list_type='singly')#
 - Methods - __init__([linked_list_type])- append(data)- Insert node with value 'data' at index -1 assuming length is more than 0. - delete(data[, index, verbosity_level])- Delete node with value 'data'. - Delete the first node in the linked list (head). - delete_last(preceding)- Delete the last node in the linked list (tail) given its predecessor. - delete_middle(preceding)- Delete the node following input node assuming that such node is not the last in the linked list. - increment_n_ops([increment])- Convenience method to increment n_ops count of the given complexity object. - insert(data, index[, verbosity_level])- Insert node with value 'data' at given index. - insert_to_empty(data)- Setup first node with value 'data' as head and also as tail in case of doubly linked list - prepend(data)- Insert node with value 'data' at index 0 assuming length is more than 0. - Convenience method to reset n_ops count of the given complexity object. - search(data)- Search for node with given value 'data'. - traverse(index[, reset_n_ops, verbosity_level])- Convenience method to traversing from head up to given index. - Attributes - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- Optional[- LinkedListNode]
 - rtype:
- int
 - rtype:
- str
 - rtype:
- str
 - rtype:
- Optional[- LinkedListNode]
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - rtype:
- str
 - append(data)#
- Insert node with value ‘data’ at index -1 assuming length is more than 0. - Parameters:
- data (Any) – Value for the node to hold. 
- Return type:
- None
 
 - property average_case_delete_time_complexity: str#
- Return type:
- str
 
 - property average_case_insert_time_complexity: str#
- Return type:
- str
 
 - property average_case_search_time_complexity: str#
- Return type:
- str
 
 - property best_case_delete_description: str#
- Return type:
- str
 
 - property best_case_delete_time_complexity: str#
- Return type:
- str
 
 - property best_case_insert_description: str#
- Return type:
- str
 
 - property best_case_insert_time_complexity: str#
- Return type:
- str
 
 - property best_case_search_description: str#
- Return type:
- str
 
 - property best_case_search_time_complexity: str#
- Return type:
- str
 
 - delete(data, index=None, verbosity_level=0)#
- Delete node with value ‘data’. If index is passed, the element at given index has to hold value equal to ‘data’. Otherwise, first entry with given value is deleted. - Parameters:
- data (Any) – Value which the node to be deleted is holding. 
- index (Optional[int] (default None)) – Index of the node to be deleted. Has to be lower than or equal to self._length. 
- verbosity_level (int (default 0)) – Select the amount of information to print throughout the deletion. One of 0, 1, 2 with 0 referring to no printing, 1 leading to printing the linked list before and after deletion and 2 meaning additionally print every element of traversal. 
 
- Return type:
- None
 
 - delete_head()#
- Delete the first node in the linked list (head). - Return type:
- None
 
 - delete_last(preceding)#
- Delete the last node in the linked list (tail) given its predecessor. - Parameters:
- preceding (LinkedListNode) – The node preceding to the node to be deleted (which is last in the linked list). 
- Return type:
- None
 
 - delete_middle(preceding)#
- Delete the node following input node assuming that such node is not the last in the linked list. - Parameters:
- preceding (LinkedListNode) – The node preceding to the node to be deleted (which is not last in the linked list). 
- Return type:
- None
 
 - property head: Optional[LinkedListNode]#
- Return type:
- Optional[- LinkedListNode]
 
 - increment_n_ops(increment=1)#
- Convenience method to increment n_ops count of the given complexity object. - Return type:
- None
 
 - insert(data, index, verbosity_level=0)#
- Insert node with value ‘data’ at given index. - Parameters:
- data (Any) – Value for the node to hold. 
- index (int) – At what position to insert the node. Must be lower than or equal to self._length. 
- verbosity_level (int (default 0)) – Select the amount of information to print throughout the insertion. One of 0, 1, 2 with 0 referring to no printing, 1 leading to printing the linked list before and after insertion and 2 meaning additionally print every element of traversal. 
 
- Return type:
- None
 
 - insert_to_empty(data)#
- Setup first node with value ‘data’ as head and also as tail in case of doubly linked list - Parameters:
- data (Any) – Value for the node to hold. 
- Return type:
- None
 
 - property n_ops: int#
- Return type:
- int
 
 - property name: str#
- Return type:
- str
 
 - prepend(data)#
- Insert node with value ‘data’ at index 0 assuming length is more than 0. - Parameters:
- data (Any) – Value for the node to hold. 
- Return type:
- None
 
 - reset_n_ops()#
- Convenience method to reset n_ops count of the given complexity object. - Return type:
- None
 
 - search(data)#
- Search for node with given value ‘data’. Index of first occurrence (from the front) of such node is returned or None of it is not found. - Parameters:
- data (Any) – Value to be held by the node. 
- Returns:
- location – Index of first occurrence of such node or None if it is not found. 
- Return type:
- Optional[int] 
 
 - property space_complexity: str#
- Return type:
- str
 
 - property tail: Optional[LinkedListNode]#
- Return type:
- Optional[- LinkedListNode]
 
 - traverse(index, reset_n_ops=False, verbosity_level=0)#
- Convenience method to traversing from head up to given index. If linked list is of type double, traverse from tail for cases when index is higher than half of length. - Parameters:
- index (int) – Index to end at with head having index 0. 
- reset_n_ops (bool (default False)) – Whether to reset self.n_ops to 0 at the beginning of the method run (False for convenience usage). 
- verbosity_level (int (default 0)) – Select the amount of information to print throughout the traversal. One of 0, 1, 2 with 0 referring to no printing, 1 leading to printing the linked list and 2 meaning additionally print every element of traversal. 
 
- Returns:
- current – None if linked list is empty or index is out of range, node at index otherwise. 
- Return type:
- LinkedListNode | None 
 
 - property worst_case_delete_description: str#
- Return type:
- str
 
 - property worst_case_delete_time_complexity: str#
- Return type:
- str
 
 - property worst_case_insert_description: str#
- Return type:
- str
 
 - property worst_case_insert_time_complexity: str#
- Return type:
- str
 
 - property worst_case_search_description: str#
- Return type:
- str
 
 - property worst_case_search_time_complexity: str#
- Return type:
- str