- package day16_course;
- import java.util.LinkedList;
- /**
- * 装饰设计模式
- * @author thinkpad
- *
- */
- class MyStack {
- private LinkedList<Object> list;
-
- public MyStack(){
- list=new LinkedList<Object>();
- }
- public void add(Object obj){
- list.addFirst(obj);
- }
- public Object get(){
-
- return list.removeFirst();
-
- }
- public boolean hasNext(){
- if(list.size()>0){
- return true;
- }else{
-
- return false;
- }
-
- }
- public int size(){
- return list.size();
- }
- }
- public class MyStackTest {
- public static void main(String[] args) {
- // 创建一个MyStack对象
- MyStack ms = new MyStack();
- ms.add("insist");
- ms.add("in");
- ms.add("dream");
- ms.add("haha");
-
- while(ms.hasNext()){
- System.out.println(ms.get());
- }
复制代码
|
|