A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 云鱼 中级黑马   /  2016-1-7 22:08  /  418 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

模拟栈内存运行,要用到哪些方法,哪位大神给个思路

1 个回复

倒序浏览
public class Demo {
        public static void main(String[] args) {
                Stack st = new Stack();
                st.in("a");
                st.in("b");
                st.in("c");
                st.in("d");
                System.out.println(st.out());
                System.out.println(st.out());
                System.out.println(st.out());
                System.out.println(st.out());
        }       
}
                        public class Stack {
                                private LinkedList list = new LinkedList();        //创建LinkedList对象
                                public void in(Object obj) {
                                        list.addLast(obj);                        //封装addLast()方法
                                }
                                public Object out() {
                                        return list.removeLast();        //封装removeLast()方法
                                }
                                public boolean isEmpty() {
                                        return list.isEmpty();                //封装isEmpty()方法
                                }
                        }
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马