0 0 votes We want to reverse elements of stack using a queue.Suppose stack operations,push and pop take 1 unit of time each and queue operations insert and delete take 2 units of time each.Assume n elements are there in the stack.The minimum time to reverse the stack is (A) 4n units (B) 6n units (C) 8n units (D) 9n units Programming in C + – PreSha 617 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
3 3 votes (B) 6n units is the answer. Lets take an example the stack is having n elements present in it. Now to reverse them using queue we have to perform two steps n times. 1. pop the element from the stack and insert it to the queue . This will take n+2n time units respectively. 2.delete the element from the queue and push it into stack.This will take 2n+n time units respectively. so the total time = 3n+3n=6n anonymous answered May 21, 2017 anonymous comment Share Follow 0 reply Please log in or register to add a comment.