Last active
January 3, 2016 02:28
-
-
Save rachtsingh/8395398 to your computer and use it in GitHub Desktop.
kind of a queue for Moritz
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
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