反转一个栈
public static void main(String[] args) {
Stack items = new Stack();
items.push("he");
items.push("saw");
items.push("a");
items.push("racecar");
reverseStack(items);
while(items.size() >0 ){
System.out.println(items.pop());
}
}
private static void reverseStack(Stack stack) {
Queue rev = new LinkedList();
while(stack.size() >0){
rev.offer(stack.pop());
}
while(rev.size() >0){
stack.push(rev.poll());
}
}