mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-05 13:49:08 -04:00
cleaning up and organizing old problems (builtin)
This commit is contained in:
parent
6afe96fa4d
commit
3fdbc2a605
106 changed files with 480 additions and 1472 deletions
src/abstract_structures
27
src/abstract_structures/queue_with_stack.py
Executable file
27
src/abstract_structures/queue_with_stack.py
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
|
||||
class Queue(object):
|
||||
def __init__(self):
|
||||
self.enq = []
|
||||
self.deq = []
|
||||
|
||||
def enqueue(self, value):
|
||||
self.enq.append(value)
|
||||
|
||||
def dequeue(self):
|
||||
if not self.deq:
|
||||
while self.enq:
|
||||
self.deq.append(self.enq.pop())
|
||||
return self.deq.pop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
q = Queue()
|
||||
|
||||
for i in range(1,10):
|
||||
q.enqueue(i)
|
||||
|
||||
for i in range(1, 10):
|
||||
print q.dequeue()
|
Loading…
Add table
Add a link
Reference in a new issue