Enqueue():
Pop() all elements from StackA to StackB one by one - O(n)
Push() new element in StackA, so it stays at the bottom- O(1).
Pop() all elements from StackB back to StackA - O(n)
So, enqueue is O(n).
Dequeue():
Just Pop().
O(1)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment