Queues and Stacks are two seemingly different types of data structures. Queues are FIFO (First In First Out) whereas Stacks are LIFO (Last in First Out)
So implementing a Queue using stacks seems a little odd.
Except it isn't.
You can easily use multiple Stacks to implement a Queue interface.
You can find the code at the below link. It is for Javascript. However, the concept remains the same irrespective of the programming language.
Moreover, the solution also runs in amortized O(1) time complexity.
https://gist.github.com/dashsaurabh/6...
#stacks #queues #algorithms #datastructures #interviewquestions
++++++++++++++++++++++++++++++++++++++++++++++++++++
My General Tech Blog : http://www.progressivecoder.com
My Web Dev Focused Blog : https://www.progressivewebninja.com
My Github URL : https://www.github.com/dashsaurabh
++++++++++++++++++++++++++++++++++++++++++++++++++++
Sound Courtesy - https://www.bensound.com/