0001 /* 0002 * 测试列表 0003 */ 0004 import dsa.*; 0005 import java.io.*; 0006 0007 public class TestList { 0008 static final int TEST_SIZE = 31; 0009 public static void main(String[] args) { 0010 List list = new List_DLNode(); 0011 while (TEST_SIZE > list.getSize()) { 0012 double dice = Math.random(); 0013 if (0.35 < dice) 0014 list.insertFirst(new Integer((int)(Math.random()*(4 * TEST_SIZE)))); 0015 else if (!list.isEmpty()) 0016 list.removeLast(); 0017 Print(list); 0018 } 0019 } 0020 0021 //输出列表中的所有元素 0022 protected static void Print(List list) { 0023 Iterator it = list.elements(); 0024 while (it.hasNext()) 0025 System.out.print(it.getNext() + " "); 0026 System.out.println(); 0027 } 0028 0029 }