Last active
December 17, 2015 22:28
-
-
Save charlierm/5681753 to your computer and use it in GitHub Desktop.
A very simple linked list in Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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