Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
snake water gam correct
Ozan Taşdemir 9/B 499
ACII_Art
learn
snake water gun game
GINGERMANZ
Два шарика в квадрате
числа близнецы
multiple inheritance
Dictionary - count characters
Please log in to post a comment.