設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)_第1頁(yè)
設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)_第2頁(yè)
設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)_第3頁(yè)
設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)_第4頁(yè)
設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩1頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí)驗(yàn)五 哈希表一、 實(shí)驗(yàn)?zāi)康模?設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)?;疽螅?1、設(shè)每個(gè)記錄有下列數(shù)據(jù)項(xiàng):電話號(hào)碼、用戶名、地址; 2、從鍵盤輸入各記錄,分別以電話號(hào)碼和用戶名為關(guān)鍵字建立哈希表; 3、采用再哈希法解決沖突; 4、查找并顯示給定電話號(hào)碼的記錄; 5、查找并顯示給定用戶名的記錄。二、思路:利用哈希表記錄:電話號(hào)碼、用戶名、地址。通過(guò)判斷來(lái)進(jìn)行相關(guān)的增加記錄、查詢記錄、姓名號(hào)碼排列、清空、退出等操作。三、結(jié)構(gòu)體定義:struct node char name8,address20; char num11; node * next; ; typedef node* pnode; typ

2、edef node* mingzi; node *phone; node *nam; node *a;四、流程圖:判斷iI=1添加I=2查詢I=3姓名I=4號(hào)碼I=5清空I=6返回判斷i退出五、代碼:/#include "iostream.h" #include <iostream> #include "string.h" #include "fstream" #define NULL 0 unsigned int key; unsigned int key2; int *p; struct node char name8

3、,address20; char num11; node * next; ; typedef node* pnode; typedef node* mingzi; node *phone; node *nam; node *a; using namespace std; void hash(char num11) int i = 3; key=(int)num2; while(numi!=NULL) key+=(int)numi; i+; key=key%20; void hash2(char name8) int i = 1; key2=(int)name0; while(namei!=NU

4、LL) key2+=(int)namei; i+; key2=key2%20; node* input() node *temp; temp = new node; temp->next=NULL; cout<<"輸入姓名:"<<endl; cin>>temp->name; cout<<"輸入地址:"<<endl; cin>>temp->address; cout<<"輸入電話:"<<endl; cin>>te

5、mp->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 = phonekey->next; phonekey->next=newphone; newname->next = namkey2->ne

6、xt; namkey2->next=newname; return 0; void create() int i; phone=new pnode20; for(i=0;i<20;i+) phonei=new node; phonei->next=NULL; void create2() int i; nam=new mingzi20; for(i=0;i<20;i+) nami=new node; nami->next=NULL; void list() int i; node *p; for(i=0;i<20;i+) p=phonei->next;

7、 while(p) cout<<"姓名:"<<p->name<<"地址:" <<p->address<<"電話號(hào)碼:"<<p->num<<endl;p=p->next; void list2() int i; node *p; for(i=0;i<20;i+) p=nami->next; while(p) cout<<"姓名:"<<p->name<<&qu

8、ot;地址:" <<p->address<<"電話號(hào)碼:"<<p->num<<endl;p=p->next; void find(char num11) hash(num); node *q=phonekey->next; while(q!= NULL) if(strcmp(num,q->num)=0) break; q=q->next; if(q) cout<<"姓名"<<q->name<<"地址:"

9、; <<q->address<<"電話號(hào)碼:"<<q->num<<endl; else cout<<"無(wú)此記錄"<<endl; void find2(char name8) hash2(name); node *q=namkey2->next; while(q!= NULL) if(strcmp(name,q->name)=0) break; q=q->next; if(q) cout<<"姓名"<<q->

10、;name<<"地址:" <<q->address<<"電話號(hào)碼:"<<q->num<<endl;else cout<<"無(wú)此記錄"<<endl; void save() int i; node *p; for(i=0;i<20;i+) p=phonei->next; while(p) fstream iiout("out.txt", ios:out); iiout<<p->name<

11、<"_"<<p->address<<"_"<<p->num<<endl; p=p->next; void menu() cout<<"1.添加記錄"<<endl; cout<<"2.查找記錄"<<endl; cout<<"3.姓名散列"<<endl;cout<<"4.號(hào)碼散列"<<endl; cout<&

12、lt;"5.清空記錄"<<endl; cout<<"6.退出系統(tǒng)"<<endl; int main() char num11; char name8; create(); create2() ; int sel; while(1) menu(); cin>>sel; if(sel=2) cout<<"8姓名查詢,9號(hào)碼查詢"<<endl; int b; cin>>b; if(b=9) cout<<"請(qǐng)輸入電話號(hào)碼:"&l

13、t;<endl; cin >>num; cout<<"輸出查找的信息:"<<endl; find(num); else cout<<"請(qǐng)輸入姓名:"<<endl; cin >>name; cout<<"輸出查找的信息:"<<endl; find2(name); if(sel=3) cout<<"姓名散列結(jié)果:"<<endl; list2(); if(sel=1) cout<<"請(qǐng)輸

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論