版權(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 林業(yè)資源管理與市場(chǎng)營(yíng)銷考核試卷
- 社會(huì)工作研究方法論考核試卷
- 錫冶煉行業(yè)政策導(dǎo)向與市場(chǎng)分析考核試卷
- 纖維素纖維在超細(xì)纖維制造技術(shù)中的發(fā)展考核試卷
- 郵政器材綠色環(huán)保設(shè)計(jì)原則考核試卷
- 鄉(xiāng)村旅游節(jié)慶活動(dòng)與事件營(yíng)銷分析
- 紅色旅游市場(chǎng)分析
- 城市規(guī)劃城市地下管線安全考核試卷
- 火力發(fā)電廠施工中的電氣設(shè)備安裝要點(diǎn)考核試卷
- 租賃設(shè)備的投資風(fēng)險(xiǎn)評(píng)估與控制考核試卷
- 護(hù)理_診斷與措施
- 如何正確處理安全生產(chǎn)綜合監(jiān)管與專業(yè)監(jiān)管的關(guān)系資料講解
- 第二章.污染物的大氣擴(kuò)散
- 水利水電工程啟閉機(jī)設(shè)計(jì)規(guī)范
- 穴位貼敷中醫(yī)治療
- 河道降水專項(xiàng)施工方案
- 村務(wù)工作總結(jié)報(bào)告范文
- 巖土工程勘察野外描述
- X射線產(chǎn)生機(jī)制
- 最新部編版二年級(jí)上冊(cè)道德與法治第二單元我們的班級(jí)測(cè)試卷6
- SLAB用戶手冊(cè)模擬重氣體泄漏的空氣擴(kuò)散模型中文簡(jiǎn)要用戶使用手冊(cè)
評(píng)論
0/150
提交評(píng)論