data_structures.linked_list.reverse_k_group =========================================== .. py:module:: data_structures.linked_list.reverse_k_group Attributes ---------- .. autoapisummary:: data_structures.linked_list.reverse_k_group.ll Classes ------- .. autoapisummary:: data_structures.linked_list.reverse_k_group.LinkedList data_structures.linked_list.reverse_k_group.Node Module Contents --------------- .. py:class:: LinkedList(ints: collections.abc.Iterable[int]) .. py:method:: __iter__() -> collections.abc.Iterator[int] >>> ints = [] >>> list(LinkedList(ints)) == ints True >>> ints = tuple(range(5)) >>> tuple(LinkedList(ints)) == ints True .. py:method:: __len__() -> int >>> for i in range(3): ... len(LinkedList(range(i))) == i True True True >>> len(LinkedList("abcdefgh")) 8 .. py:method:: __str__() -> str >>> str(LinkedList([])) '' >>> str(LinkedList(range(5))) '0 -> 1 -> 2 -> 3 -> 4' .. py:method:: 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 .. py:method:: 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' .. py:attribute:: head :type: Node | None :value: None .. py:class:: Node .. py:attribute:: data :type: int .. py:attribute:: next_node :type: Node | None :value: None .. py:data:: ll