You are viewing a single comment's thread. Return to all comments →
My Python 2 implementation:
class MyQueue(object): def __init__(self): self.mouth = [] self.butt = [] def peek(self): self.digest() return self.butt[-1] def pop(self): self.digest() return self.butt.pop() def put(self, value): self.mouth.append(value) def digest(self): if len(self.butt) == 0: while len(self.mouth) > 0: self.butt.append(self.mouth.pop())
Seems like cookies are disabled on this browser, please enable them to open this website
Queues: A Tale of Two Stacks
You are viewing a single comment's thread. Return to all comments →
My Python 2 implementation: