Skip to content

Instantly share code, notes, and snippets.

@Aaron1011
Last active December 10, 2015 11:28
Show Gist options
  • Save Aaron1011/4427456 to your computer and use it in GitHub Desktop.
Save Aaron1011/4427456 to your computer and use it in GitHub Desktop.
Reverse a linked list
import copy
class Node:
def __init__(self, data, next=None):
self.data = data
self.next = next
def __str__(self):
return "<Node %s>" % self.data
def linkedlreverse(start, end=None, last=None):
if start.next == end:
start.next = last
return start
start_copy = copy.copy(start)
start.next = last
print "Start: ", start, start.next
return linkedlreverse(start_copy.next, end, start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment