sum=1;
adr=s0%M;
d=adr;
if(hlist[adr].k==s0)
{
gotoxy(18,18);printf("");
gotoxy(18,18);printf("%s",hlist[d].name);
gotoxy(18,19);printf("%s",hlist[d].py);
gotoxy(18,20);
printf("搜索%d次",sum);
getch();
}
else
{if(hlist[adr].k==0)
{gotoxy(18,18);
printf("无记录!
");
getch();
}
else
{g=0;
for(i=0;g==0;i++)
{d=(d+s0%10+1)%M;/*伪随机*/
sum=sum+1;
if(hlist[d].k==0)
{gotoxy(18,18);
printf("无记录!
");
g=1;getch();
};
gotoxy(18,18);
printf("%s",hlist[d].name);
gotoxy(18,19);
printf("%s",hlist[d].py);
gotoxy(18,20);
printf("搜索%d次",sum);
getch();
if(hlist[d].k==s0)
{g=1;
gotoxy(18,21);
printf("搜索%d次成功!
",sum);
getch();
};
};
};
};
}
/***************************************/
voidinp()/*输入表*/
{
char*f;
intr,s0;
oldlist[0].name="桂芳芳";oldlist[0].py="guifanfan";
oldlist[1].name="姚建飞";oldlist[1].py="yaojianfei";
oldlist[2].name="杨扬";oldlist[2].py="yangyang";
oldlist[3].name="朱玉环";oldlist[3].py="zhuyuhuang";
oldlist[5].name="陈曦";oldlist[5].py="chenxi";
oldlist[6].name="张雷";oldlist[6].py="zhanglei";
oldlist[7].name="盛永海";oldlist[7].py="shenyonghai";
oldlist[8].name="陈道全";oldlist[8].py="chengdaoquan";
oldlist[9].name="陆道清";oldlist[9].py="ludaoqing";
oldlist[10].name="龚云祥";oldlist[10].py="gongyunxiang";
oldlist[11].name="孙振兴";oldlist[11].py="sunzhenxing";
oldlist[12].name="孙容飞";oldlist[12].py="sunrongfei";
oldlist[13].name="孙明龙";oldlist[13].py="sunminglong";
oldlist[14].name="张浩";oldlist[14].py="zhanghao";
oldlist[15].name="田苗";oldlist[15].py="tianmiao";
oldlist[16].name="姚建中";oldlist[16].py="yaojianzhong";
oldlist[17].name="姚建清";oldlist[17].py="yaojianqing";
oldlist[18].name="姚建华";oldlist[18].py="yaojianhua";
oldlist[19].name="张海峰";oldlist[19].py="yaohaifeng";
oldlist[20].name="陈言号";oldlist[20].py="chengyanhao";
oldlist[21].name="姚秋锋";oldlist[21].py="yaoqiufeng";
oldlist[22].name="钱鹏程";oldlist[22].py="qianpengcheng";
oldlist[23].name="姚海峰";oldlist[23].py="yaohaifeng";
oldlist[24].name="卞艳";oldlist[24].py="bianyan";
oldlist[25].name="凌蕾";oldlist[25].py="linglei";
oldlist[26].name="李伟";oldlist[26].py="liwei";
oldlist[27].name="黄海燕";oldlist[27].py="huanhaiyan";
oldlist[28].name="刘殿琴";oldlist[28].py="liudianqin";
oldlist[29].name="李云";oldlist[29].py="liyun";
/*
请在此输入数据,同时修改程序开头的M LN
*/
for(i=0;i{
s0=0;
f=oldlist[i].py;
for(r=0;*(f+r)!
='\0';r++){s0=*(f+r)+s0;};
oldlist[i].k=s0;
};
}
/****************************************/
voiddhash()/*显示哈希表*/
{charLON=17;
clrscr();
if(LON>L){LON=L;};
gotoxy(1,1);printf("哈希表:
copyrightby姚建飞2003.6");
gotoxy(1,2);printf("地址:
");
for(i=0;i{gotoxy(1,i+3);
printf("%-3d",i);
};
gotoxy(9,2);printf("关键字:
");
for(i=0;i{gotoxy(10,i+3);
printf("%-6d",hlist[i].k);
};
gotoxy(19,2);printf("姓名:
");
for(i=0;i{gotoxy(19,3+i);
printf("%s",hlist[i].name);
};
gotoxy(28,2);printf("拼音:
");
for(i=0;i{gotoxy(28,i+3);
printf("%s",hlist[i].py);
};
gotoxy(40,2);printf("搜索长度:
");
for(i=0;i{gotoxy(43,i+3);
printf("%2d",hlist[i].si);
};
gotoxy(53,2);printf("H(key):
");
for(i=0;i{gotoxy(53,i+3);
printf("%2d",(hlist[i].k)%M);
};
average=0;
for(i=0;i{average=average+hlist[i].si;};
average=average/N;
gotoxy(10,23);
printf("平均搜索长度:
ASL(%d)=%f",N,average);
gotoxy(20,24);
printf("任意键下一屏!
");
ch1=getch();
if(L>15)
{
clrscr();
if(LON>L-15){LON=L-15;};
gotoxy(1,1);printf("哈希表:
copyrightby姚建飞2003.6");
gotoxy(1,2);printf("地址:
");
for(i=0;i{gotoxy(1,i+3);
printf("%-3d",i+15);
};
gotoxy(9,2);printf("关键字:
");
for(i=0;i{gotoxy(10,i+3);
printf("%-6d",hlist[i+15].k);
};
gotoxy(19,2);printf("姓名:
");
for(i=0;i{gotoxy(19,3+i);
printf("%s",hlist[i+15].name);
};
gotoxy(28,2);printf("拼音:
");
for(i=0;i{gotoxy(28,i+3);
printf("%s",hlist[i+15].py);
};
gotoxy(40,2);printf("搜索长度:
");
for(i=0;i{gotoxy(43,i+3);
printf("%2d",hlist[i+15].si);
};
gotoxy(53,2);printf("H(key):
");
for(i=0;i{gotoxy(53,i+3);
printf("%2d",(hlist[i+15].k)%M);
};
average=0;
for(i=0;i{average=average+hlist[i].si;};
average=average/N;
gotoxy(10,23);
printf("平均搜索长度:
ASL(%d)=%f",N,average);
gotoxy(20,24);
printf("任意键下一屏!
");
ch1=getch();
};
if(L>30)
{
clrscr();
if(LON>L-30){LON=L-30;};
gotoxy(1,1);printf("哈希表:
copyrightby姚建飞2003.6");
gotoxy(1,2);printf("地址:
");
for(i=0;i{gotoxy(1,i+3);
printf("%-3d",i+30);
};
gotoxy(9,2);printf("关键字:
");
for(i=0;i{gotoxy(10,i+3);
printf("%-6d",hlist[i+30].k);
};
gotoxy(19,2);printf("姓名:
");
for(i=0;i{gotoxy(19,3+i);
printf("%s",hlist[i+30].name);
};
gotoxy(28,2);printf("拼音:
");
for(i=0;i{gotoxy(28,i+3);
printf("%s",hlist[i+30].py);
};
gotoxy(40,2);printf("搜索长度:
");
for(i=0;i{gotoxy(43,i+3);
printf("%2d",hlist[i+30].si);
};
gotoxy(53,2);printf("H(key):
");
for(i=0;i{gotoxy(53,i+3);
printf("%2d",(hlist[i+30].k)%M);
};
average=0;
for(i=0;i{average=average+hlist[i].si;};
average=average/N;
gotoxy(10,23);
printf("平均搜索长度:
ASL(%d)=%f",N,average);
gotoxy(20,24);
printf("任意键下一屏!
");
ch1=getch();
};
if(L>45)
{
clrscr();
if(LON>L-45){LON=L-45;};
gotoxy(1,1);printf("哈希表:
copyrightby姚建飞2003.6");
gotoxy(1,2);printf("地址:
");
for(i=0;i{gotoxy(1,i+3);
printf("%-3d",i+45);
};
gotoxy(9,2);printf("关键字:
");
for(i=0;i{gotoxy(10,i+3);
printf("%-6d",hlist[i+45].k);
};
gotoxy(19,2);printf("姓名:
");
for(i=0;i{gotoxy(19,3+i);
printf("%s",hlist[i+45].name);
};
gotoxy(28,2);printf("拼音:
");
for(i=0;i{gotoxy(28,i+3);
printf("%s",hlist[i+45].py);
};
gotoxy(40,2);printf("搜索长度:
");
for(i=0;i{gotoxy(43,i+3);
printf("%2d",hlist[i+45].si);
};
gotoxy(53,2);printf("H(key):
");
for(i=0;i{gotoxy(53,i+3);
printf("%2d",(hlist[i+45].k)%M);
};
average=0;
for(i=0;i{average=average+hlist[i].si;};
average=average/N;
gotoxy(10,23);
printf("平均搜索长度:
ASL(%d)=%f",N,average);
gotoxy(20,24);
printf("任意键返回!
");
ch1=getch();
};
}
/**************************************/
voidmain()
{inp();/*输入原表*/
chash();/*建哈希表*/
a:
clrscr();
gotoxy(21,2);
textcolor(GREEN);
cprintf("欢迎使用本程序------------编者:
姚建飞");
printf("\n");
gotoxy(22,4);
textcolor(GREEN);
cprintf("1.显示哈希表");
printf("\n");
gotoxy(22,6);
textcolor(GREEN);
cprintf("2.查找");
printf("\n");
gotoxy(22,8);
textcolor(GREEN);
cprintf("x.退出");
printf("\n");
gotoxy(22,12);
cprintf("请输入选择:
");
printf("\n");
gotoxy(24,14);
ch1=getch();
if(ch1==0x78){textcolor(GREEN);
cprintf("谢谢使用本程序,你已经退出本程序!
");printf("\n");exit();};/*"x":
退出*/
if(ch1==0x31){dhash();};/*表的属性*/
if(ch1==0x32){findhlist();};/*查找*/
gotoa;
}