Skip to content

Instantly share code, notes, and snippets.

@gustavoatt
Created August 1, 2012 08:44
Show Gist options
  • Save gustavoatt/3225094 to your computer and use it in GitHub Desktop.
Save gustavoatt/3225094 to your computer and use it in GitHub Desktop.
List reverse
#!/usr/bin/env python
class List(object):
def __init__(self):
self.val = None
self.next = None
def add(self, val):
current = self
while current.next is not None:
current = current.next
current.val = val
current.next = List()
def reverse(self):
current = self
previous = None
while current.next is not None:
following = current.next
current.next = previous
previous = current
current = following
return previous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment