data_structures.linked_list.reverse_k_group

Attributes

ll

Classes

LinkedList

Node

Module Contents

class data_structures.linked_list.reverse_k_group.LinkedList(ints: collections.abc.Iterable[int])
__iter__() collections.abc.Iterator[int]
>>> ints = []
>>> list(LinkedList(ints)) == ints
True
>>> ints = tuple(range(5))
>>> tuple(LinkedList(ints)) == ints
True
__len__() int
>>> for i in range(3):
...     len(LinkedList(range(i))) == i
True
True
True
>>> len(LinkedList("abcdefgh"))
8
__str__() str
>>> str(LinkedList([]))
''
>>> str(LinkedList(range(5)))
'0 -> 1 -> 2 -> 3 -> 4'
append(data: int) None
>>> ll = LinkedList([1, 2])
>>> tuple(ll)
(1, 2)
>>> ll.append(3)
>>> tuple(ll)
(1, 2, 3)
>>> ll.append(4)
>>> tuple(ll)
(1, 2, 3, 4)
>>> len(ll)
4
reverse_k_nodes(group_size: int) None

reverse nodes within groups of size k >>> ll = LinkedList([1, 2, 3, 4, 5]) >>> ll.reverse_k_nodes(2) >>> tuple(ll) (2, 1, 4, 3, 5) >>> str(ll) ‘2 -> 1 -> 4 -> 3 -> 5’

head: Node | None = None
class data_structures.linked_list.reverse_k_group.Node
data: int
next_node: Node | None = None
data_structures.linked_list.reverse_k_group.ll