Possible stack sequence problems
The first premise is that the stack must be in accordance with the order into the stack, such as 1, 2, 3, 4 in the order, if the first out of 4, then the advanced stack in sequence 1, 2, 3, 4,
Then the stack, so that the first is 4, no other elements can be in the stack, so only in order out of the stack, so the order of the stack is 4, 3, 2, 1.
If the order of the stack is 3, 4, 2, 1, you must first analyze the situation of 3, only the first 1, 2, 3 into the stack, and then 3 out of the stack. And then into the stack 4, and then out of the stack 4, 2, 1.
If the order of the stack is 3, 2, 4, 1 or 3, 2, 1, 4, first the 1, 2, 3 into the stack, again out of the stack 3, 2, if this is the front of the sequence, the Advanced 4, and then out of the stack 4, 1, if it is the back of the stack order out of 1, and then into the stack 4, and then out of the stack 4, so you will get the above sequence.
can be judged according to the following method: If the stack order is 1234, given a stack sequence, such as 2431, it is legal.
Because for each number in the stack sequence, all numbers behind it, which are smaller than it, must be in descending order.
For example: if the stack sequence is 4123, obviously does not meet the above requirements, because for 4, it later than its small number sequence of 123, accumulator, so is not a legitimate stack sequence.
If the stack is 3142, it is also illegal, because 3 is smaller than the 1 and 2 is not descending order.
If the stack is 1234, then it is legal, because for each number, there is no smaller number behind it.
This method is used to rule out the wrong stack order.