Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StackUsingTwoQueues {
- var mainQueue = [Int]()
- var tempQueue = [Int]()
- func push(item: Int) {
- mainQueue.append(item)
- }
- func pop() -> Int {
- if mainQueue.isEmpty {
- return -1
- }
- while mainQueue.count > 1 {
- tempQueue.append(mainQueue.removeFirst())
- }
- let popped = mainQueue.removeFirst()
- mainQueue = tempQueue
- tempQueue = []
- return popped
- }
- }
- let stack = StackUsingTwoQueues()
- stack.push(item: 5)
- stack.push(item: 6)
- stack.push(item: 7)
Add Comment
Please, Sign In to add comment