每日日报2020 10/8

今天我在菜鸟教程上发现了一个好玩的东西。原来数组可以玩出这么多花来的吗?数据结构真的是一门神奇的学科。留下一段代码,证明我来过。

import java.util.*;

public class StackDemo {

static void showpush(Stack<Integer> st, int a) {
st.push(new Integer(a));
System.out.println("push(" + a + ")");
System.out.println("stack: " + st);
}

static void showpop(Stack<Integer> st) {
System.out.print("pop -> ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("stack: " + st);
}

public static void main(String args[]) {
Stack<Integer> st = new Stack<Integer>();
System.out.println("stack: " + st);
showpush(st, 42);
showpush(st, 66);
showpush(st, 99);
showpop(st);
showpop(st);
showpop(st);
try {
showpop(st);
} catch (EmptyStackException e) {
System.out.println("empty stack");
}
}
}

posted @ 2020-10-08 21:57  宋振兴  阅读(33)  评论(0编辑  收藏  举报