Skip to content

Instantly share code, notes, and snippets.

@charlierm
Last active December 17, 2015 22:28
Show Gist options
  • Save charlierm/5681753 to your computer and use it in GitHub Desktop.
Save charlierm/5681753 to your computer and use it in GitHub Desktop.
A very simple linked list in Python.
import random
class Item:
next = None
data = 0
def __init__(self):
self.data = random.random()
class LinkedList:
head = None
length = 0
def add(self, item):
item.next = self.head
self.head = item
self.length += 1
def iterate(self):
head = self.head
while head is not None:
yield head
head = head.next
ll = LinkedList()
for i in range(0,100):
item = Item()
ll.add(item)
for i in ll.iterate():
print(i.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment