下载此文档

哈希表及其应用 (2).doc


文档分类:IT计算机 | 页数:约11页 举报非法文档有奖
1/11
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/11 下载此文档
文档列表 文档介绍
#include""
# include <>
# include <>
# include <>
#include<iostream>
using namespacess;
cout<<"输入电话 :";
cin>>[i].nNum;
[i].key = x;
stored[i]=1;
}
else printf("error occurred!");
}
return ht;
}
int search(HashTable ht,int x) //ht:散列表 ele:待查找结点
{
int i,add;
i=Hash(ht,x);
if(stored[i]==1&&[i].key==x)
return i;
else
{
add=i;
i=(i+1)%;
while(i!=add && stored[i]==1 && [i].key != x)
i=(i+1)%;
if([i].key==x)
return i;
else
{
printf("can not find!");
return -1;
}
}
}
void delet(HashTable ht,int x) //ht:散列表 ele:待删除结点
{
int i;
i=search(ht,x);
if(i!=-1)
{
stored[i]=0;
}
else printf("error occurred!");
}
int hash(hashtable ht2,int x)//数据除表长得关键字
{
return x%ht2->len;
}
void addht2(hashtable &ht2,int n)
{
int i;
ElemNode *p;
i=hash(ht2,n);
p=(ElemNode *)malloc(sizeof(ElemNode));
p->key=n;
cout<<"姓名 :";
cin>>p->;
cout<<"地址 :";
cin>>p->;
cout<<"号码 :";
cin>>p->;
p->next=ht2[i].first;
ht2[i].first=p;
}
void InitHashTable(hashtable ht2,int n)//链地址法创建哈希表
{
int i;
ht2->len=n;
for(i=0;i<max;i++)
ht2[i].first=NULL;// 关键字的first域初始为NULL
}
void Insert(hashtable ht2,int x)//x为要插入的数据
{
int i;
ElemNode *p;
i=hash(ht2,x);
p=(ElemNode *)malloc(sizeof(ElemNode));
p->key=x;
cout<<"姓名 :";
cin>>p->;
cout<<"地址 :";
cin>>p->;
cout<<"号码 :";
cin>>p->;
p->next=ht2[i].first;
ht2[i].first=p; // 将p结点连接到相应关键字结点后面
}
int Search(hashtable ht2,int x)//找到关键字
{
int i;
ElemNode *p;
i=hash(ht2,x);
p=ht2[i].first;
while(p !=NULL && p->key != x)
p=p->next;
if(p!=NULL)
return 1;
else return 0;
}
int display1(HashTable ht)
{
int i;
//for(i=0;i<;i++)
// printf("%3d",i);
// printf("\n");
for(i=0;i<;i++)

哈希表及其应用 (2) 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数11
  • 收藏数0 收藏
  • 顶次数0
  • 上传人1542605778
  • 文件大小35 KB
  • 时间2022-01-25