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?.
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?.
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.