Also, you can’t use pointers
This question is an interview question and sounds confusing to me as stack ADT is given and operations on queue are asked…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In a queue enqueuing always insert the data at the riht-most filled position, in a stack also the data is inserted at the last(top). So, emulating enqueuing operation on a stack is not difficult. One push() operation will suffice. The problem is with the dequeuing operation. One way to emulate dequeue is to use two instances of the stack and on dequeue request empty stack 1 into stack 2 and then pop from stack 2 then restore stack 1 with stack2.