Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Reverse linked-list in-place
""" Reverse linked-list in-place. Complexity: O(n) time and O(1) space. Author: Jayesh Chandrapal """ class Node: def __init__(self, value, next = None): self.value = value self.next = next def reverse(head): current = head previous = None next = None while current is not None: next = current.next current.next = previous previous = current current = next return previous def printlist(head): result = "" current = head while current: result += str(current.value) + " -> " current = current.next print(result) head = Node(10, Node(20, Node(30))) printlist(head) head = reverse(head) printlist(head)
run
|
edit
|
history
|
help
0
myone
31 dec dil khush
Fiboncaci series in recursion
Generating subsets
Bubble sort
Recursive Fibonacci
Ghost 👻👻👻👻👻 Game 👻👻👻👻👻👻
Me good good
PySuper
ort