数据结构与算法分析——c语言描述 练习5.5e 答案
hashQuad.c
#include"hashQuad.h"
#include"fatal.h"
#include<math.h>
#include<string.h>
#define MinTableSize 5
enum KindOfEntry { Legitimate, Empty, Deleted };
struct HashEntry {
ElementType element;
enum KindOfEntry info;
};
typedef struct HashEntry Cell;
struct HashTbl {
int tableSize;
int hasInsertedNum;
Cell *theCells;//数组
int* randomArr;
};
static int RandInt(int i, int j) {
int temp;
temp = (int)(i + (1.0*rand() / RAND_MAX)*(j - i));
return temp;
}
static void getRandomInt(int *A, int n) {
for (int i = 0; i < n; i++) {
A[i] = i + 1;
}
for (int i = 1; i < n; i++) {
//std::swap(A[i], A[RandInt(0, i)]);
int randAdrr = RandInt(0, i);
int t = A[i];
A[i] = A[randAdrr];
A[randAdrr] = t;
}
}
static int hash(ElementType key, int tableSize) {
return key