public class StackDemo {
private int[] arr = new int[1000];
private int flag = 0;
//Stringbuffer同理 增加
public void add(int x) {
if( flag == arr.length ) {
int[] arrnew = new int[arr.length * 2];
for(int i = 0; i < arr.length; i++) {
arrnew[i] = arr[i];
}
arr = arrnew;
}
arr[flag] = x;
flag++;
}
//Integer和Int差不多,但可以为空 查询
public Integer get() {
if(flag == 0) {
return null;
}
flag--;
return arr[flag];
}
}
public class Stack {
public static void main(String[] args) {
StackDemo x = new StackDemo();
for(int i = 0; i < 10000; i++) {
x.add(i);
}
System.out.println(x.get());
System.out.println(x.get());
System.out.println(x.get());
}
}