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
nnnn
Faiha Lesson 1, 2020: Python Basics
.....✓[Guess the number]®®®®®®®•$$$$✓.....
PyMenuClass
What regex will match these lines?
PySlots3
Phython
Linked Lists in python
filtering python3
GINGERMANZ