Data into the stack: 1234567
Solution Ideas:
A simple simulation of the stack into the stack operation, the elements sequentially into the stack. The stack is then sequentially based on the order entered. For example, the given stack order is 1 4 3 7 6 2 5, first put 1 into the stack, found that the first in the input data is exactly 1. will be 1 out of the stack, the following is 4, because the stack is empty, and just put 1 into the stack, and then 2 3 4 sequentially into the stack, when the stack top element is 4, and the second element of the input data equal, 4 out of the stack. Then 3 out of the stack, the next processing 7, because the top element of the stack is 2,7 greater than 2, so the next 5 6 7 into the stack (the element in the stack is 7 6 5 2). Then the top element of the stack is equal to 7 of the input data, 7 out of the stack, and then 6 is equal, 6 out of the stack. At this point the stack element (5 2), the input data to be judged is 2 5. 2 compared to the top of the stack 2<5, so this sequence is not possible out of the stack order.
Write an algorithm to determine if the stack order is correct