Created
July 11, 2012 01:44
-
-
Save sing1ee/3087416 to your computer and use it in GitHub Desktop.
double stack queue
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
# !/usr/bin/python | |
# -*- encoding: utf-8 -*- | |
class DoubleStackQueue: | |
def __init__(self): | |
self.first_stack = [] | |
self.second_stack = [] | |
def en_queue(self, el = None): | |
self.first_stack.append(el) | |
def de_queue(self): | |
if len(self.second_stack) == 0: | |
while len(self.first_stack) != 0: | |
self.second_stack.append(self.first_stack.pop()) | |
return self.second_stack.pop() | |
if __name__ == '__main__': | |
queue = DoubleStackQueue() | |
queue.en_queue(1) | |
queue.en_queue(2) | |
print queue.de_queue() | |
print queue.de_queue() | |
queue.en_queue(3) | |
print queue.de_queue() | |
print queue.de_queue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment