views:

124

answers:

1

I was browsing through some interview questions and stumbled upon this. It got me tearing my hair apart.

Does anyone know how to implement a stack using queue?.

+4  A: 

push: insert the element into the back of the queue.

pop: remove an element from the front, insert it immediately in the back, repeat N-1 times, where N is the size of the queue, then remove the last element and return it.

I refreshed the page right before I started answering only to find this answer posted already =( Good job! =)
Beemer