清单2.1 array.java程序 public class ArrayApp { public static void main(String[] args) { long[] arr; arr = new long[100]; int nElems=0; int j; long searchKey; arr[0]=77; arr[1]=99; arr[2]=44; arr[3]=55; arr[4]=22; arr[5]=88; arr[6]=11; arr[7]=00; arr[8]=66; arr[9]=33; nElems=10; for(j=0;j<nElems;j++) System.out.print(arr[j]+" "); System.out.println(" "); searchKey = 66; for(j=0;j<nElems;j++) if(arr[j]==searchKey) break; if(j== nElems) System.out.println("can't find"+searchKey); else System.out.println("found "+searchKey); searchKey =55; for(j=0;j<nElems;j++) if(arr[j]==searchKey) break; for(int k=j;k<nElems;k++) arr[k]=arr[k+1]; nElems--; for(j=0;j<nElems;j++) System.out.print(arr[j]+" "); System.out.println(" "); } } 清单2.2 lowArray.java程序 class LowArray { private long[] a; public LowArray(int size) { a = new long[size]; } public void setElem(int index, long value) { a[index] = value; } public long getElem(int index) { return a[index]; } } public class LowArrayApp { public static void main(String[] args) { LowArray arr; arr = new LowArray(100); int nElems = 0; int j; arr.setElem(0, 77); arr.setElem(1, 99); arr.setElem(2, 44); arr.setElem(3, 55); arr.setElem(4, 22); arr.setElem(5, 88); arr.setElem(6, 11); arr.setElem(7, 00); arr.setElem(8, 66); arr.setElem(9, 33); nElems = 10; for (j = 0; j < nElems; j++) System.out.print(arr.getElem(j) + " "); System.out.println(" "); int searchKey = 26; for (j = 0; j < nElems; j++) if (arr.getElem(j) == searchKey) break; if (j == nElems) System.out.println("can't find" + searchKey); else System.out.println("found" + searchKey); for (j = 0; j < nElems; j++) if (arr.getElem(j) == 55) break; for (int k = j; k < nElems; k++) arr.setElem(k, arr.getElem(k + 1)); nElems--; for (j = 0; j < nElems; j++) System.out.print(arr.getElem(j) + " "); System.out.println(" "); } } 清单2.3 highArray.java class HighArray { private long[] a; private int nElems; public HighArray(int max) { a = new long[max]; nElems = 0; } public void insert(long value) { a[nElems] = value; nElems++; } public void display() { for (int j = 0; j < nElems; j++) { System.out.print(a[j] + " "); } System.out.println(" "); } public boolean find(long searchKey) { int j; for (j = 0; j < nElems; j++) { if (a[j] == searchKey) break; } if (j == nElems) return false; else return true; } public boolean delete(long value) { int j; for (j = 0; j < nElems; j++) if (value == a[j]) break; if (j == nElems) return false; else { for (int k = j; k < nElems; k++) a[k] = a[k + 1]; nElems--; return true; } } } public class HighArrayApp { public static void main(String[] args) { int maxSize = 100; HighArray arr; arr = new HighArray(maxSize); arr.insert(77); arr.insert(99); arr.insert(44); arr.insert(55); arr.insert(22); arr.insert(88); arr.insert(11); arr.insert(00); arr.insert(66); arr.insert(33); arr.display(); int searchKey = 35; if (arr.find(searchKey)) System.out.println("Found" + searchKey); else System.out.println("can't Find" + searchKey); arr.delete(00); arr.delete(55); arr.delete(99); arr.display(); } } /*out: **77 99 44 55 22 88 11 0 66 33 **can't Find35 **77 44 22 88 11 66 33 */