Linked List, Queue, and Stack Implementations in Python

Graham's Code

Screen Shot 2013-05-23 at 3.37.05 PM
# Programmer: Graham Nedelka
# Linked List, Queue, and Stack Implementations

import random

class Node(object):

def __init__(self, other = None):
self.other = other = None
self.previous = None

def __str__(self):
return str(self.other)

class List(object):
def __init__(self):
self.head = None
self.tail = None

def append(self, value):

newNode = Node(value)
if self.head == None:
self.head = newNode
self.tail = newNode

else: = newNode
newNode.previous = self.tail
self.tail = newNode

def __str__(self):
someString = “”
current = self.head
while current != None:
someString = someString + current.other
current =
return someString

class Queue(List):
def enqueue(self, value):

def dequeue(self):
self.temp = self.head
self.head =
return self.temp

class Stack(List):
def push(self, value):

def pop(self):
self.temp = self.tail
self.tail = self.tail.previous
return self.temp

def main():
list1 = List()
for i in xrange(0, 100):
print list1
queue = Queue()
for i in xrange(0,100):
for i in xrange(0,100):
print queue.dequeue()

View original post 26 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s