Answer: Two
A queue can be
implemented using two stacks.
A queue follows the
order of FIFO (First in First out). To obtain this order using Stack, which
follows FILO (First in Last out) we need two stacks.
Let M and N are two stacks
Enqueue: Push new element onto M.
Dequeue: If N is empty, fill it by
popping each element from M and push it onto N.
Now pop and return the top element from
N. This gives the FIFO order
0 comments:
Post a Comment