Simulate the set of stack data structures with the consumer list and test it. The consumer List Data Structure
1/* 2 * requirement: use consumer list to simulate a set of stack data structures, and Test 3 * create a class to encapsulate the Linked method 4 */5 public class demo4_shortlist {6 public static void main (String [] args) {7 Stack stack = new Stack (); 8 stack. in ("a"); 9 stack. in ("B"); 10 stack. in ("c"); 11 stack. in ("d"); 12 while (! Stack. isEmpty () {13 System. out. println (stack. out (); 14} 15} 16}
1 import java. util. shortlist; 2 3 public class Stack {4 @ SuppressWarnings ("rawtypes") 5 private shortlist list = new shortlist (); 6 7 @ SuppressWarnings ("unchecked ") 8 public void in (Object obj) {// simulate stack 9 list. addLast (obj); 10} 11 12 public Object out () {// simulate stack 13 return list. removeLast (); 14} 15 16 public boolean isEmpty () {// judge whether it is empty 17 return list. isEmpty (); 18}