#include #include #include #define MAX 100 void Search1(int a[], int n, int key){ int i=0; a[n] = key; while(a[i] != key){ i++; } if(i == n){ printf("\n未找到。\n\n"); } else { printf("\n此数在第 %d 位。\n\n", i + 1); } } void Search2(int a[], int n, int key){ int low = 0, high = n-1, mid; while(low <= high){ mid = (low + high) / 2; if(a[mid] == key){ printf("\n此数在第 %d 位。\n\n", mid + 1); return; } else if (a[mid] > key){ high = mid - 1; } else { low = mid + 1; } } printf("\n未找到。\n\n"); } void InitHashList(int b[]){ int i; for (i = 0; i < MAX; i++) b[i] = 0; } int Hash(int key){ return (key * 3) % 7; } int Insert(int a[], int b[], int e){ int d = Hash(e); int temp = d; while (b[d] != 0){ d = (d + 1) % 7; if (d == temp){ printf("散列表已满\n"); return 0; } } a[d] = e; b[d] = 1; return 1; } int Search3(int a[], int b[], int key){ int d = Hash(key); int temp = d; int p = b[d]; while (p != 0){ if (a[d] == key){ return d; } else { d = (d + 1) % 7; p = b[d]; } if(temp == d){ break; } } return -1; } void start_hash(int a[], int b[]){ int n, e; InitHashList(a); InitHashList(b); printf("请输入需要输入的元素个数:"); scanf("%d",&n); for(int i=0; i