哈希表算法(版)_哈希表算法实例

2020-02-28 其他范文 下载本文

哈希表算法(版)由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“哈希表算法实例”。

#include

#include

#include

#define No_key-1

#define No_data-1

#define Max_num 13

int visit;

typedefstruct ele

{

int data;

int key;

}Elemtype;

typedefstruct hashtable

{

Elemtype elem[Max_num];

int count;

int sizeindex;

}HashTable;

int Hash(int key)

{

return key%13;

}

int CreateHas(HashTable H)

{

int succe=0;

int i;

int c;

Elemtype elem;

printf(“please enter the data:n”);for(i=0;i

{

elem.key=rand()%100;

scanf(“%d”,&elem.data);

printf(“the key is:%4dn”,elem.key);c=Hash(elem.key);

while(!succe)

{

visit++;

if(H.elem[c].key==No_key){

H.elem[c]=elem;H.count++;

succe=1;

}

else

if(c>=13)

c=0;

else c++;

}

succe=0;

}

return 1;

}

void main()

{

HashTable H;

int i;

visit=0;

H.count=0;

H.sizeindex=15;

srand((time(NULL)));

for(i=0;i

{

H.elem[i].data=No_data;

H.elem[i].key=No_key;

}

CreateHas(H);

for(i=0;i

printf(“%4d”,H.elem[i].data);

printf(“n”);

printf(“查¨¦找¨°次ä?数ºy:êon”);printf(“%dn”,visit);

printf(“平?均¨´查¨¦找¨°次ä?数ºy:êon”);printf(“%dn”,visit/13);

}

《哈希表算法(版).docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
哈希表算法(版)
点击下载文档
相关专题 哈希表算法实例 算法 哈希表 哈希表算法实例 算法 哈希表
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文