hash表的实现
更新时间:2024-06-02 05:10:01 阅读量: 综合文库 文档下载
hash表的实现
#include
int hash(KeyType k)
{
return k%p;
} void init()
{ int i;
for(i=0;i ht[i]=0; } void insert(KeyType k) { int d,i; d=hash(k); for(i=0;i ht[(i+d)%M]=k; } int search(KeyType k) { int i,d; d=hash(k); if(ht[d]==k) return d; else { for(i=1;i if(i d=(d+i)%M; return d; } else return -1; } } void print() { int i; for(i=0;i } void main() /*{ KeyType k; init(); printf(\scanf(\while(k!=0) { insert(k); scanf(\ } print(); printf(\ scanf(\if(search(k)!=-1) printf(\ else printf(\ }*/ int result; char h,select; //clrscr(); printf(\ printf(\ \ printf(\ printf(\线性表的顺序表示--------------------- \ printf(\ lable0: printf(\线性表L不存在,是否创建线性表L(Y/N)?:\ h=getch(); if(h=='y'||h=='Y') result=init(); else goto end; if(result==0||result==-1){printf(\线性表初始长度不合法,必须是大于或等于1!!\ lable0;} if(result==2) goto lable1; lable1: //clrscr(); printf(\ printf(\ *********************************************************** \ printf(\printf(\ 恭喜你!线性表L已创建好, 继续操作! \ printf(\printf(\ 1.插入新的数据元素请按 I \ printf(\ printf(\ 2.表尾插入新的数据元素 请按 p \ printf(\printf(\ 3.删除表中数据元素请按 D \ printf(\printf(\ 4.删除表尾元素请按 K \ printf(\ printf(\ 5.清空线性表请按 Q \ printf(\ printf(\ 6.返回线性表表长请按 F \ printf(\ printf(\ 7.查找数据元素请按 L \ printf(\ printf(\ 8.输出线性表元素请按 V \ printf(\ printf(\ *********************************************************** \ printf(\ printf(\ 请输入你的选择:\ select=getch(); if(select=='i'||select=='I') { int i,e; int flag1; printf(\请输入插入位置和元素值:\ scanf(\flag1=insertlist(i,e); if(flag1==0 ||flag1==1) {printf(\插入位置不合法或扩充存储空间失败,是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else {printf(\插入元素成功!是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } } else if(select=='p'||select=='P') { int i,e; int flag1; printf(\请输入插入元素值:\ scanf(\flag1=append(e); if(flag1==1) {printf(\扩充存储空间失败,是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else {printf(\插入元素成功!是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } } else if(select=='d'||select=='D') { int i,e; int flag1; printf(\请输入删除元素的位序:\ scanf(\flag1=deletelist(i); if(flag1==0) {printf(\删除元素不存在或是空表,操作失败!,是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else {printf(\删除元素成功!是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } } else if(select=='k'||select=='K') { int i,e; int flag1; flag1=deletelist_end(); if(flag1==0) {printf(\是空表,操作失败!,是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else {printf(\删除表尾元素成功!是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } } else if(select=='q'||select=='Q') { clearlist(); printf(\清空线性表成功!是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else if(select=='f'||select=='F') { printf(\当前线性表长度为:\printf(\ printf(\是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else if(select=='l'||select=='L') { int i,e; int flag1; printf(\请输入要查找的元素值:\ scanf(\flag1=find(e); printf(\if(flag1==0) {printf(\是空表,或该数据元素不存在!,是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else { printf(\找到了,是L中的第\ printf(\printf(\个数据元素\ printf(\ printf(\是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } } else if(select=='v'||select=='V') { int i,e; int flag1; printf(\当前表中数据元素有:\ flag1=print(); if(flag1==0) {printf(\是空表!\printf(\ printf(\是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } else { printf(\是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } } else { printf(\选择有误!是否继续(Y/N)?\ select=getch(); if(select=='y'||select=='Y') goto lable1; goto end; } end:; }
正在阅读:
hash表的实现06-02
学前教育原理的名词解释和简答题07-05
《管理学原理》综合练习题,附答案04-05
2015新增工程院院士03-03
提高初中语文阅读教学效率的策略-最新资料12-27
数据中心双机备份系统解决方案05-11
DSP技术及应用实验报告 实验四10-26
设备、管道防腐施工工艺标准10-02
自考教育学(二)历年4月考试真题答案 - 课程代码00442 - 图文02-03
S120控制单元cu320 调试纪录06-30
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 实现
- hash
- 无砟轨道 结构病害分析及养护维修技术之轨道板裂缝问题 - 图文
- 电光源原理复习题及答案
- “引导高中生正确进行异性交往”资料
- 小学三年级上册书法练习指导全册教案
- 生物技术专业自我介绍推荐
- 特超高产玉米种植技术研究
- 国际货币体系概述习题与答案
- VB复习资料
- 扎哈哈迪德
- 中国偏光板行业市场前景分析预测报告(目录) - 图文
- 2018年贵州省黔西南州中考数学试卷
- 基于C#的USB3.0接口程序设计
- 第四单元第8题操作步骤
- 崇明岛拓展训练心得体会
- 海珠区2007学年第二学期期末调研测试语文科
- 要想孩子脑子好,十种食品不可少 - 图文
- 置业顾问实习总结6篇
- 关于贫困地区县域经济的思考
- 侍 氏 人 物 (转自侍氏家谱网)
- 2016年三年级下册数学期末复习计划