hash表的实现

2019-04-16 00:00

hash表的实现

#include #define M 13 typedef int KeyType; KeyType ht[M]; int p=13;

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')

{


hash表的实现.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:如何做好企业的工程项目管理

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: