/*
* 自定义栈集合。
*/
public class MyStack {
private LinkedList link;
public MyStack() {
link = new LinkedList();
}
public void add(Object obj) {
link.addFirst(obj);
}
public Object get(int index) {
return link.get(index);
}
public int size() {
return link.size();
}
}
测试:
public class LinkedListTest {
public static void main(String[] args) {
// 创建集合对象
MyStack ms = new MyStack();