一.hash函数头文件实现hash.h
#ifndef __HASH_H__
#define __HASH_H__
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<unistd.h>
#define N 11
typedef int datatype;
typedef struct hastbl
{
datatype *h;
int length;
}hash_tbl,*hash_tp;
extern void init_hash(hash_tp *hp,int m);
extern void create_hash(hash_tp hp,datatype *a);
extern int hash_search(hash_tp hp,int key);
extern void hash_show(hash_tp hp,int hash_val);
#endif
二.hash函数函数实现hash.c
#include"hash.h"
int p;
void init_hash(hash_tp *hp,int m)
{
(*hp) = malloc(sizeof(hash_tbl));
if(NULL == *hp)
{
perror("malloc");
exit(1);
}
(*hp)->length = m;
(*hp)->h =(datatype*)malloc((*hp)-&

本文详细介绍了使用C语言实现哈希表的过程,包括通过除留余数法构建哈希函数,采用开放定值法中的线性探测来处理冲突。同时,提供了哈希表的初始化、创建、查找和显示的函数实现,以及主函数中对这些操作的调用。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



