1 import java.util.LinkedList; 2 3 public class Test5 { 4 5 public static void main(String[] args) { 6 7 Duilie dl = new Duilie(); 8 9 dl.myAdd("abc1"); 10 dl.myAdd("abc2"); 11 dl.myAdd("abc3"); 12 dl.myAdd("abc4"); 13 14 while (!dl.isNull()) 15 { 16 System.out.println(dl.myGet()); 17 } 18 19 } 20 21 } 22 23 class Duilie{ 24 private LinkedList link; 25 26 public Duilie(){ 27 link = new LinkedList(); 28 } 29 30 public void myAdd(Object obj) 31 { 32 link.addLast(obj); 33 } 34 35 public Object myGet() 36 { 37 // return link.removeFirst();//模拟队列 38 return link.removeLast(); //模拟堆栈 39 } 40 41 public boolean isNull() 42 { 43 return link.isEmpty(); 44 } 45 }
时间: 2024-10-10 09:06:02