通过三种hash函数将数据散列到对应的键值当中,而对于有冲突的键用链表储存数据。在这里只是用链表保存了与字符串首字母对应的指针,散列表的大小一般选择素数。参考书目《数据结构与算法分析》
//接口函数
#ifndef _HASH_H
#define _HASH_H
struct listnode
{
char *str;
struct listnode *Next;
};
typedef struct listnode ListNode;
typedef ListNode *Position;
struct HashTab
{
int TableSize;
Position *TheLists;
};
typedef struct HashTab *HashTable;
HashTable InitTable(int TableSize);
void DestroyTable(HashTable H);
Position Find(char *str,HashTable H);
void Insert(char *str,HashTable H);
void VisitAllList(HashTable H);
#endif
//接口函数定义
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash.h"
#define MinTableSize 2
typedef int Index;
Index Hash(const char *Key,int TableSize)//三种hash函数映射
{
unsigned int HashVal=0;
while