What does the push-in and pop-up of the stack mean?

enter two integer sequences, the first representing the push-in order of the stack, and the second indicating whether it is the pop-up order of the stack. It is assumed that all the numbers pressed are not equal.

for example, stack pressing order: 1. The pop-up sequence can be 4, 5, 3, 3, 1, 1 or 4, 3, 5, and 1

.

I don"t understand what it means. Isn"t the pop-up order 5-4-3-2-1?


this I came from Baidu:
for example, the sequence 1, 2, 3, 4, 5, 5 is the push-in order of a stack, and the sequence 4, 5, 5, 3, and 2 is a pop-up sequence corresponding to the stack sequence, but 4, 4, 3, 5, 5, 5, and 1, 2 is not the pop-up sequence of the stack sequence.

ideas:

set up an auxiliary stack s, press sequence 1, 2, 3, 4, and 5 into the auxiliary stack s in turn, and pop up numbers from the auxiliary stack s in the order of the second sequence, 4, 5, 5, 3, 3, 2, and 1.

first, the sequence 1, 2, 3, 4, 5 is pressed into stack s in turn, and each time the stack is pressed, it is judged whether the current top element of stack s is equal to the first element of sequence 4, 5, 5, 3, 2, and 1. When 4 is pressed, it is found that the top element of the stack is equal to the first element of the sequence 4, 5, 3, 2, and 1. Pop up the stack top element 4 of stack s, and then remove the first element from sequence 4, 5, 5, 3, 2, and 1, and turn sequence 4, 5, 5, 3, 2, and 1 into sequence 5, 5, 3, 2, and 1. Performing the above process.

import java.util.Stack;

/*
 * 
 * 
 * 
 * 1,2,3,4,5
 * 45,3,2,1
 * 4,3,5,1,2
 * */

public class q21_stack {

    public static void main(String[] args) {
        int [] pushA = {1,2,3,4,5,6,7,8};
        int [] popA = {7,8,6,4,5,3,2,1};
        System.out.println(IsPopOrder(pushA,popA));
    }

    public static boolean IsPopOrder(int [] pushA,int [] popA)
    {
        if(pushA.length<=0 || popA.length<=0 )
        {
            return false;
        }
        int j=0;
        Stack<Integer> s1=new Stack<Integer>();
        for(int i=0;i<pushA.length;iPP)
        {
            s1.push(pushA[i]);
            if(pushA[i] == popA[j])
            {
                if(jPP==popA.length-1)
                {
                    return true;
                }
                s1.pop();
            }
        }
        while(!s1.isEmpty())
        {
            if(s1.pop()!=popA[jPP])
            {
                return false;
            }
        }
        return true;
    }
}

means to press one and test the stack sequence once. LZ, when you say 54321, it should be the order in which all 12345 is pressed in and then popped up, but this means to press and play at the same time.

the case of the code affixed to PS: is as follows: sequence 4, 5, 5, and 3, 2, and 1 is a pop-up sequence corresponding to the stack sequence, but 4, 3, 5, 5, and 1, 2, can not be the pop-up sequence of the stack sequence.

and LZ your question means that 45321 is OK, and 43512 is OK. Then you have to change the code!

The

posted code contains the first one that only judges the pop-up sequence, and the
LZ title means that 43512 should also be established

.

explain the push-in and pop-up of the lower stack: for example, to manipulate an array, press in is push and pop-up is pop.

such as: press the stack sequence: 1 br 2, 3, 4, 5, judge, pop-up sequence can be 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,

implement it in code:

var arr = []
arr.push(1)
arr.push(2)
arr.push(3)
arr.push(4)
arr.pop()
arr.push(5)
arr.pop()
arr.pop()
arr.pop()
arr.pop()

second: (more special)
1
1, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,

implement it in code:

var arr = []
arr.push(1)
arr.push(2)
arr.push(3)
arr.push(4)
arr.pop()
arr.pop()
arr.push(5)
arr.pop()
arr.shift()
arr.shift()
arr[1,2] pop12 arr.shift()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34afa-4eb9a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34afa-4eb9a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?