Solution to Queue With Two Stacks from Jobdu

1 Aug

Question (in Chinese):

Question Name: Queue With Two Stacks

Question Description: simulate a queue class with two stacks. Write a test program for the queue. If queue is empty and pop, print -1.

Input: the first list is an integer, saying the number of instructions in the following lines. Otherwise, each line is an instruction: either “POP” or “PUSH val” (val is an integer).

Output: the popped result.

 This question is the same as the problem 3.5 from Cracking the Coding Interview.

Leave a Reply

Your email address will not be published. Required fields are marked *