欢迎来到天天文库
浏览记录
ID:39473696
大小:70.50 KB
页数:8页
时间:2019-07-04
《哈希表实验操作》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.源程序或过程:#include#include#defineNIL0#defineDelNIL-1#definem13#definen20typedefstruct{intkey;}LHashTable;voidHashListinit(LHashTableHT[n]){inti;for(i=0;i2、%m);}intHashListsearch(LHashTableHT[n],intk){intd,temp;d=Hash(k);temp=d;while(HT[d].key!=NIL){if(HT[d].key==k)returnd;elsed=(d+1)%n;if(d==temp)return-1;}return-1;7第页}voidHashListinsert(LHashTableHT[n],intk){intd,temp;d=Hash(k);temp=d;while(HT[d].key!=NIL&&HT[d].key!=DelNIL){d=(d+1)%n;3、if(d==temp){printf("哈希表无空间");exit(1);}}HT[d].key=k;}voidHashListDelete(LHashTableHT[n],intk){intd,temp;d=Hash(k);temp=d;while(HT[d].key!=NIL){if(HT[d].key==k){HT[d].key=DelNIL;return;}elsed=(d+1)%n;if(d==temp)break;}printf("哈希表中无待删除元素%d",k);exit(1);}voidprintHashList(LHashTableHT[n]){4、inti;for(i=0;i5、"所建立的哈希表为:");printHashList(HT);printf("");printf("请输入要删除的关键字:");scanf("%d",&k);HashListDelete(HT,k);printf("删除成功后的哈希表为:");printHashList(HT);printf("");}结果或分析:7第页2.源程序或过程:#include#include#defineNULL0#definem13#definen20typedefstructnodetype{intkey;structnod6、etype*next;}CHashTable;voidHashListinit(CHashTable**HT){inti;for(i=0;inext;HashListDelete(HT,p->key);p=HT[i];}}}intHash(in7、tk){returnk%m;}intHashListsearch(CHashTable**HT,intk){intd;CHashTable*p;d=Hash(k);p=HT[d];while(p!=NULL){if(p->key==k)return1;elsep=p->next;}return0;}voidHashListinsert(CHashTable**HT,intk){intd;CHashTable*p;d=Hash(k);p=(CHashTable*)malloc(sizeof(CHashTable));p->key=k;p->next=HT[d];HT8、[d]=p
2、%m);}intHashListsearch(LHashTableHT[n],intk){intd,temp;d=Hash(k);temp=d;while(HT[d].key!=NIL){if(HT[d].key==k)returnd;elsed=(d+1)%n;if(d==temp)return-1;}return-1;7第页}voidHashListinsert(LHashTableHT[n],intk){intd,temp;d=Hash(k);temp=d;while(HT[d].key!=NIL&&HT[d].key!=DelNIL){d=(d+1)%n;
3、if(d==temp){printf("哈希表无空间");exit(1);}}HT[d].key=k;}voidHashListDelete(LHashTableHT[n],intk){intd,temp;d=Hash(k);temp=d;while(HT[d].key!=NIL){if(HT[d].key==k){HT[d].key=DelNIL;return;}elsed=(d+1)%n;if(d==temp)break;}printf("哈希表中无待删除元素%d",k);exit(1);}voidprintHashList(LHashTableHT[n]){
4、inti;for(i=0;i5、"所建立的哈希表为:");printHashList(HT);printf("");printf("请输入要删除的关键字:");scanf("%d",&k);HashListDelete(HT,k);printf("删除成功后的哈希表为:");printHashList(HT);printf("");}结果或分析:7第页2.源程序或过程:#include#include#defineNULL0#definem13#definen20typedefstructnodetype{intkey;structnod6、etype*next;}CHashTable;voidHashListinit(CHashTable**HT){inti;for(i=0;inext;HashListDelete(HT,p->key);p=HT[i];}}}intHash(in7、tk){returnk%m;}intHashListsearch(CHashTable**HT,intk){intd;CHashTable*p;d=Hash(k);p=HT[d];while(p!=NULL){if(p->key==k)return1;elsep=p->next;}return0;}voidHashListinsert(CHashTable**HT,intk){intd;CHashTable*p;d=Hash(k);p=(CHashTable*)malloc(sizeof(CHashTable));p->key=k;p->next=HT[d];HT8、[d]=p
5、"所建立的哈希表为:");printHashList(HT);printf("");printf("请输入要删除的关键字:");scanf("%d",&k);HashListDelete(HT,k);printf("删除成功后的哈希表为:");printHashList(HT);printf("");}结果或分析:7第页2.源程序或过程:#include#include#defineNULL0#definem13#definen20typedefstructnodetype{intkey;structnod
6、etype*next;}CHashTable;voidHashListinit(CHashTable**HT){inti;for(i=0;inext;HashListDelete(HT,p->key);p=HT[i];}}}intHash(in
7、tk){returnk%m;}intHashListsearch(CHashTable**HT,intk){intd;CHashTable*p;d=Hash(k);p=HT[d];while(p!=NULL){if(p->key==k)return1;elsep=p->next;}return0;}voidHashListinsert(CHashTable**HT,intk){intd;CHashTable*p;d=Hash(k);p=(CHashTable*)malloc(sizeof(CHashTable));p->key=k;p->next=HT[d];HT
8、[d]=p
此文档下载收益归作者所有