Skip to content

Instantly share code, notes, and snippets.

@rachtsingh
Last active January 3, 2016 02:28
Show Gist options
  • Save rachtsingh/8395398 to your computer and use it in GitHub Desktop.
Save rachtsingh/8395398 to your computer and use it in GitHub Desktop.
kind of a queue for Moritz
class Queue():
def __init__(self):
self.elementarray = [0] * 25 # initialize to 25 0s for now (basically) empty
self.head = 0
self.tail = 0
def push(self, element):
self.elementarray[self.tail] = element # basically set the tail'th element to be 'element'
self.tail += 1 # shift the tail number
def pop(self):
if (self.head != self.tail): # if they're not at the same position
value = self.elementarray[self.head]
self.head += 1 # shift the head number
return value # give the dude a value
a = Queue()
a.push(5)
a.push(7)
a.push(8)
print(a.pop()) # gives out 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment