Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- S1 -> S2
- X -> S1
- S2 -> S1
- """
- class Queue:
- def __init__(self):
- self.OneStack = []
- self.TwoStack = []
- def Push(self, Val):
- while(self.OneStack):
- self.TwoStack.append(self.OneStack.pop())
- self.OneStack.append(Val)
- while(self.TwoStack):
- self.OneStack.append(self.TwoStack.pop())
- def Pop(self):
- print(self.OneStack.pop())
- def Top(self):
- print(self.OneStack[-1])
- ObjQueue = Queue()
- ObjQueue.Push(1)
- ObjQueue.Push(2)
- ObjQueue.Push(4)
- ObjQueue.Pop()
- ObjQueue.Top()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement