| 34 | |
| 35 | |
| 36 | class Queue: |
| 37 | |
| 38 | def __init__(self): |
| 39 | self.stack_one = Stack() |
| 40 | self.stack_two = Stack() |
| 41 | |
| 42 | def push(self, value): |
| 43 | if self.stack_two.empty(): |
| 44 | self.stack_two.push(value) |
| 45 | else: |
| 46 | self.stack_one.push(value) |
| 47 | |
| 48 | def pop(self): |
| 49 | |
| 50 | pop_result = self.stack_two.pop() |
| 51 | if self.stack_two.empty(): |
| 52 | while 1: |
| 53 | if self.stack_one.empty(): |
| 54 | break |
| 55 | |
| 56 | self.stack_two.push(self.stack_one.pop()) |
| 57 | |
| 58 | return pop_result |
| 59 | |
| 60 | def peek(self): |
| 61 | |
| 62 | return self.stack_two.get_top() |
| 63 | |
| 64 | |
| 65 | queue = Queue() |
no outgoing calls
no test coverage detected