Example #1
0
def reverse_sll_2(sll: Singlellist) -> Singlellist:
    if len(sll) == 1:
        return sll
    head = sll.remove_first()
    head.next = None
    reverse_sll_2(sll).tail.next = head
    sll.tail = head
    return sll
Example #2
0
def reverse_sll_loop(sll: Singlellist) -> Singlellist:
    if len(sll) == 1:
        return sll
    head = sll.head
    prev_node = None
    curr_node = sll.head
    while curr_node is not None:
        next_node = curr_node.next
        curr_node.next = prev_node
        prev_node = curr_node
        curr_node = next_node

    sll.head = sll.tail
    sll.tail = head