- package com.heima.zuoye;
- import java.util.LinkedList;
- public class Stack {
- LinkedList list = new LinkedList<>();
-
- public void in(Object obj) {
- list.addLast(obj);
- }
-
- public Object out() {
- return list.removeLast();
- }
-
- public Boolean isEmpty() {
- return list.isEmpty();
- }
-
- }
-
复制代码- package com.heima.zuoye;
- public class Demo2_LinkList {
- public static void main(String[] args) {
- Stack s = new Stack();
- s.in("a");
- s.in("b");
- s.in("c");
- s.in("d");
-
- while(!s.isEmpty()){
- System.out.println(s.out());
- }
- }
- }
复制代码
|