#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转载请标明出处.