#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct HashTable{
int tableSize;
struct HashBody *body;
};
struct HashBody{
int data;
int state;
};
int nextPrime(int num){
num++;
int i;
while(1){
int q=sqrt(num);
for(i=2;i<=q;i++){
if(num%i==0){
break;
}
}
if(i>q){
return num;
}
num++;
}
}
struct HashTable *createTable(int size){
struct HashTable *H;
H=(struct HashTable *)malloc(sizeof(struct HashTable));
H->tableSize=nextPrime(size);
H->body=(struct HashBody *)malloc(sizeof(struct HashBody)*H->tableSize);
for(int i=0;i<H->tableSize;i++){
H->body[i].state=0;
}
return H;
}
int Hash(int num,int size){
return num%size;
}
int Find(struct HashTable *H,int num){
int pos,Newpos;
int shift=0;
pos=Hash(num,H->tableSize);
Newpos=pos;
while(H->
哈希表的基本操作(平方探测法,C语言)
最新推荐文章于 2025-01-05 16:59:48 发布
该博客介绍了哈希表的创建、插入、查找、删除和显示等基本操作。通过C语言实现了一个哈希表结构,使用平方探测法解决冲突,并提供了示例代码展示如何在哈希表中插入和删除元素,以及查看哈希表当前状态。

最低0.47元/天 解锁文章
1774

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



