Computer Science, asked by uday710, 4 months ago

Write a program to implement a queue using two stacks such that the in linear time and the dequeue operation runs in constant time in c++​

Answers

Answered by ezhilharish196
0

Answer:

Implementation of Queue using two Stacks

Enqueue operation:

Simply push the elements into the first stack.

Dequeue operation:

Pop from the second stack if the second stack is not empty.

If second stack is empty, pop from the first stack and push all the elements into second until the first stack becomes empty.

Now pop an element from the second stack.

Similar questions