Singly Linked List¶
-
class
data_structures.linked_list.singly.
SinglyLinkedList
(*args)¶ This is the simple singly linked list:
have only one head point, no tail pointer
- Parameters
args –
-
append
(value: Any) → None¶ Append a node after the tail of this singly linked list
- Parameters
value (Any) –
- Returns
- Return type
None
-
insert_after
(value: Union[data_structures.linked_list.nodes.SinglyNode, Any], node: Optional[data_structures.linked_list.nodes.SinglyNode] = None) → None¶ If after_node is not provided, the given value will be insert to the beginning of this singly linked list
-
pop
() → data_structures.linked_list.nodes.SinglyNode¶ Pop the last node of this singly linked list
- Returns
- Return type
-
remove_after
(node: Optional[data_structures.linked_list.nodes.SinglyNode] = None) → None¶ Remove one node after the give node
- Parameters
node (Optional[Node]) – If after_node is not provided, the first node of this singly linked list will be removed
- Returns
- Return type
None
-
replace
(old: Any, new: Any, max_: Optional[int] = None) → None¶ In-place replace the node old value with the given new one
- Complexity:
Space: Θ(n), Ο(n), Ω(1)
Time: Θ(n), Ο(n), Ω(1)
- Parameters
old (Any) – The old value to be replaced
new (Any) – The new value to replace the old one
max (Optional[int]) – if max is not provided all of nodes equaled to old will be changed to new
- Returns
This method is a in-place change and returns None
- Return type
None
-
reverse
() → None¶ In-place reverse
- Returns
- Return type
None
-
search_iter
(value: Any) → data_structures.linked_list.singly.SinglyLinkedListSearchIterator¶ Search for a given value, return a iterator
- Parameters
value (Any) –
- Returns
- Return type
Iterator
-
class
data_structures.linked_list.singly.
CircularSinglyLinkedList
(*args)¶ - Parameters
args –
-
append
(value: Any) → None¶ - Parameters
value (Any) –
- Returns
- Return type
None
-
pop
() → data_structures.linked_list.nodes.SinglyNode¶ - Returns
- Return type
-
reverse
() → None¶ In-place reverse
- Returns
- Return type
None
-
search_iter
(value: Any)¶ - Parameters
value (Any) –
- Returns