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

其他范文 时间:2020-02-28 10:30:00 收藏本文下载本文
【www.daodoc.com - 其他范文】

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

#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);

}

下载哈希表算法(版)word格式文档
下载哈希表算法(版).doc
将本文档下载到自己电脑,方便修改和收藏。
点此处下载文档

文档为doc格式

    热门文章
      整站推荐
        点击下载本文