91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-26
  • 語言: C/C++
  • 標簽: 哈希表??

資源簡介

1、設每個記錄有下列數據項:電話號碼、用戶名、地址; 2、從鍵盤輸入各記錄,分別以電話號碼和用戶名為關鍵字建立哈希表; 3、采用再哈希法解決沖突; 4、查找并顯示給定電話號碼的記錄; 5、查找并顯示給定用戶名的記錄。 6、在哈希函數確定的前提下,嘗試各種不同類型處理沖突的方法(至少兩種),考察平均查找長度的變化。

資源截圖

代碼片段和文件信息

//#include?“iostream.h“?
#include??
#include?
#include?“string.h“?
#include?“fstream“?
#define?NULL?0?
unsigned?int?key;?
unsigned?int?key2;?
int?*p;?
struct?node?//建節點?
{?
char?name[8]address[20];?
char?num[11];?
node?*?next;?
};?

typedef?node*?pnode;?
typedef?node*?mingzi;?
node?**phone;?
node?**nam;?
node?*a;?

using?namespace?std;?//使用名稱空間?

void?hash(char?num[11])?//哈希函數?
{?
int?i?=?3;?
key=(int)num[2];?

while(num[i]!=NULL)?
{?
key+=(int)num[i];?
i++;?
}?
key=key%20;?
}?

void?hash2(char?name[8])?//哈希函數?
{?
int?i?=?1;?
key2=(int)name[0];?
while(name[i]!=NULL)?
{?
key2+=(int)name[i];?
i++;?
}?
key2=key2%20;?
}?

node*?input()?//輸入節點?
{?
node?*temp;?
temp?=?new?node;?
temp->next=NULL;?
cout<<“輸入姓名:“<cin>>temp->name;?
cout<<“輸入地址:“<cin>>temp->address;?
cout<<“輸入電話:“<cin>>temp->num;?
return?temp;?
}?

int?apend()?//添加節點?
{?
node?*newphone;?
node?*newname;?
newphone=input();?
newname=newphone;?
newphone->next=NULL;?
newname->next=NULL;?
hash(newphone->num);?
hash2(newname->name);?
newphone->next?=?phone[key]->next;?
phone[key]->next=newphone;?
newname->next?=?nam[key2]->next;?
nam[key2]->next=newname;?
return?0;?
}?

void?create()?//新建節點?
{?
int?i;?
phone=new?pnode[20];?
for(i=0;i<20;i++)?
{?
phone[i]=new?node;?
phone[i]->next=NULL;?
}?
}?
void?create2()?//新建節點?
{?
int?i;?
nam=new?mingzi[20];?
for(i=0;i<20;i++)?
{?
nam[i]=new?node;?
nam[i]->next=NULL;?
}?
}?
void?list()?//顯示列表?
{?
int?i;?
node?*p;?
for(i=0;i<20;i++)?
{?
p=phone[i]->next;?
while(p)?
{?
cout<name<<‘_‘<address<<‘_‘<num<p=p->next;?
}?
}?
}?
void?list2()?//顯示列表?
{?
int?i;?
node?*p;?
for(i=0;i<

評論

共有 條評論