One, using two stacks to simulate a queue
Idea One:
1. One stack s1 as the data store, and the other stack S2, as a temporary data store.
2. S1 the data when the team is in the queue
3. Out of the team will S1 pop, and press people S2, and then pop S2 in the top of the data, and then the rest of the data pop s2, and pressure people S1.
Idea two:
1. One stack s1 as the data store, and the other stack S2, as a temporary data store.
2. When the team, determine whether the S1, is empty, if not empty, the data will be pressed into the S1, if it is empty, the data in S2 will be poured into S1, in the data pressure people s1.
3. When the team, Judge S2, whether empty, if not empty, the data directly pops up S2, if it is empty, the data in S1 will be poured into S2, and then pop the data at the top of the S2.
Three ideas:
1. Press the data into the S1 when you queue.
2. When the team is out, determine if S2 is empty, and if not empty, the top element is ejected directly, or if empty, the S1 data is poured into S2 and the top element of the S2 is ejected.
Web Front end Interview series-data structure (two stacks simulate a queue)