嗨,我正在尝试使用另一个空堆栈反转堆栈(我自己编写了一个堆栈)。由于某种原因,它无法正常工作。谁能帮我这个 ?
public static void main(String[] args) { Stack stack1 = new Stack(); //filling the stack with numbers from 0 to 4 for(int i = 0; i < Constants.MAX_ELMNTS; i++){ stack1.push(new Integer(i)); System.out.println(i); } Stack reverse = new Stack(); while(stack1.getNbElements() > 0){ reverse.push(stack1.pop()); }
while(!stack1.isEmpty()){ Integer value = (Integer)stack1.pop(); System.out.println(value); reverse.push(value); }