MCPcopy Index your code
hub / github.com/HuberTRoy/leetCode / Queue

Class Queue

Stack/ImplementQueueUsingStack.py:36–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35
36class 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
65queue = Queue()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected