Skip to content

Instantly share code, notes, and snippets.

@KushalP
Created April 5, 2010 20:19
Show Gist options
  • Save KushalP/356823 to your computer and use it in GitHub Desktop.
Save KushalP/356823 to your computer and use it in GitHub Desktop.
class LinkedList(object):
"""
Attempting to learn the basics of ADTs again.
Note to self: don't ever use this, stick with list() methods
"""
class Node(object):
def __init__(self, item):
self.value = item
self.next = None
def __init__(self, item=None):
if item is not None:
self.head = Node(item); self.tail = self.head
else:
self.head = None; self.tail = None
def append(self, item):
if not self.head:
self.head = Node(item)
self.tail = self.head
elif self.tail:
self.tail.next = Node(item)
self.tail = self.tail.next
else:
self.tail = Node(item)
def __iter__(self):
cursor = self.head
while cursor:
yield cursor.value
cursor = cursor.next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment