今天我试图在java.util.Stack课堂上推进,然后Iterator通过项目使用迭代(不使用pop).我期待着LIFO的财产但却感到惊讶.
这是我正在尝试的代码.
import java.util.*;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
RobStack<Integer> rstack = new RobStack<Integer>(); // Correct Implementation
Stack<Integer> jstack = new Stack<Integer>(); // Default Java Implementation
rstack.push(0); jstack.push(0);
rstack.push(1); jstack.push(1);
rstack.push(2); jstack.push(2);
rstack.push(3); jstack.push(3);
System.out.print("Algo Stack: ");
for (int i : rstack)
System.out.print(i + " ");
System.out.print("\nJava Stack: ");
for (int i : jstack)
System.out.print(i + " ");
}
}
Run Code Online (Sandbox Code Playgroud)
以上程序的输出如下:
Algo Stack: 3 2 1 0
Java Stack: …Run Code Online (Sandbox Code Playgroud)