题目要求
功能要求:
(1)初始化三列文件;
(2)向散列文件中插入一个元素;
(3)从散列文件中删除一个元素;
(4)从散列文件中查找一个元素。
散列文件通常采用链接法处理冲突。
散列文件中每个节点的类型定义为:
Struct FLNode
{ //散列主文件中的节点类型
ElemType data ; //值域
Int next; //指向下一个节点的指针域
};
代码实现
主函数 main.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "biao.h"
int main()
{
int com;
while(1)
{
Introduce();
scanf("%d",&com);
switch(com)
{
case 1:Create();break;//初始化散列文件
case 2:MN();Insert();break;//向散列文件中插入一个元素
case 3:MN();Delete();break;//从散列文件中删除一个元素
case 4:MN();Find();break;//从散列表中查找一个元素
case 5:MN();Printff();break;//输出散列表中的全部元素
case 6:system("cls");break;
case 7:exit(1);break;
default :printf("没有该操作,请重新输入:\n");
}
}
return 0;
}
头文件 biao.h
#ifndef BIAO_H_INCLUDED
#define BIAO_H_INCLUDED
typedef int ElemType;
typedef struct FLNode
{
ElemType data;
int next;
}FLNode;
int m,n;//n是要生成散列表的长度,m是<=n的最小素数
char dizhi[1000];//存放散列文件的地址
char * moren;//存储默认文件的地址
FLNode *biao;//读取文件信息后的存放地址
void Create();
void Insert();
void Printff();
int qiusushu(int a);
void MN();//计算m,n
void Delete();
void Find();
void Introduce();
#endif // BIAO_H_INCLUDED
功能介绍 Introduce.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "biao.h"
void Introduce()
{
printf("*******************1表示初始化散列文件*********************\n");
printf("*******************2表示向散列文件中插入一个元素***********\n");
printf("*******************3表示从散列文件中删除一个元素***********\n");
printf("*****4表示从散列表中查找一个元素是否存在,并返回比较次数***\n");
printf("*******************5表示输出散列表中的全部元素*************\n");
printf("*******************6表示清屏*******************************\n");
printf("*******************7表示退出系统***************************\n");
}
初始化散列文件 Create.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#