package 索引查找;import java.util.Scanner;public class IndexSearch { public static long stu[] = { 1080101,1080102,1080103,1080104,1080105,1080106,0,0,0,0, 1080201,1080202,1080203,1080204,0,0,0,0,0,0, 1080301,1080302,1080303,1080304,0,0,0,0,0,0 }; static Item[]indexTable = { new Item(10801,0,6), new Item(10802,10,4), new Item(10803,20,4) }; public static int indexSearch(int key){ int i,index1,start = 0,length = 0; index1 = key/100; for (i = 0;i= indexTable.length) { return -1; } for (i = start;i = indexTable.length) { return -1; } //保存关键字到主表中 stu[start+length] = key; indexTable[i].length++; return 0; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("原始数据:"); for (int i = 0;i = 0) {// System.out.printf("查找成功,该关键字位于数组的第%d个位置\n",pos);// }else{// System.out.println("查找失败!");// } System.out.println("输入插入的关键字"); int num = input.nextInt(); if (insertNode(num) == -1) { System.out.println("插入失败!"); }else { for (int i = 0;i
package 索引查找; import java.util.Scanner; public class IndexSearch { public static long stu[] = { 1080101,1080102,1080103,1080104,1080105,1080106,0,0,0,0, 1080201,1080202,1080203,1080204,0,0,0,0,0,0, 1080301,1080302,1080303,1080304,0,0,0,0,0,0 }; static Item[]indexTable = { new Item(10801,0,6), new Item(10802,10,4), new Item(10803,20,4) }; public static int indexSearch(int key){ int i,index1,start = 0,length = 0; index1 = key/100; for (i = 0;i= indexTable.length) { return -1; } for (i = start;i = 0) { System.out.printf("查找成功,该关键字位于数组的第%d个位置\n",pos); }else{ System.out.println("查找失败!"); } } }