定义结构体
#define ElemType int
#define P 7
typedef struct HashNode{
ElemType data;
HashNode* link;
}HashNode;
typedef HashNode* HashTable[P];//表里存的是个地址,这是个HashNode*类型的数组
//如HashTable[i] 表示指向第一个结点的地址
实现方法
#include "HashTable.h"
/*
*初始化
*/
void InitHashTable(HashTable &ht) {
for (int i = 0; i <P; i++){
ht[i] = NULL;
}
}
/*
*插入
*/
void InsertHashTable(HashTable &ht, ElemType x) {
int index = Hash(x);
HashNode* s = (Hash