0001 /* 0002 * 测试向量 0003 */ 0004 import dsa.*; 0005 import java.io.*; 0006 0007 public class TestVector { 0008 static final int TEST_SIZE = 31; 0009 public static void main(String[] args) { 0010 Vector vec = new Vector_ExtArray(); 0011 // Vector vec = new Vector_Array(); 0012 while (TEST_SIZE > vec.getSize()) { 0013 double dice = Math.random(); 0014 if (0.35 < dice) 0015 vec.insertAtRank((int)(Math.random()*(1 + vec.getSize())), new Integer((int)(Math.random()*(4 * TEST_SIZE)))); 0016 else if (!vec.isEmpty()) 0017 vec.removeAtRank((int)(Math.random()*vec.getSize())); 0018 Print(vec); 0019 } 0020 } 0021 0022 //输出向量中的所有元素 0023 protected static void Print(Vector v) { 0024 for (int i = 0; i < v.getSize(); i++) 0025 System.out.print(v.getAtRank(i) + " "); 0026 System.out.println(); 0027 } 0028 0029 }