Demo entry 6718470

asdf

   

Submitted by anonymous on Mar 05, 2018 at 04:08
Language: Java. Code size: 378 Bytes.

    public void push(int node) {
        stack1.push(node);
    }
    
    public int pop() {
        //大部分情况下,stack1作为push栈,stack2作为pop栈
        //只有当pop栈空的时候,把stack1中所有数据转移到stack2中,使得pop有元素可以pop
    	if(stack2.isEmpty()){
            while( !stack1.isEmpty() ){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).