雙向鏈表課程設(shè)計(jì)報(bào)告_第1頁(yè)
雙向鏈表課程設(shè)計(jì)報(bào)告_第2頁(yè)
雙向鏈表課程設(shè)計(jì)報(bào)告_第3頁(yè)
雙向鏈表課程設(shè)計(jì)報(bào)告_第4頁(yè)
雙向鏈表課程設(shè)計(jì)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩22頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、 VC課程設(shè)計(jì)報(bào)告課 程: VC+課程設(shè)計(jì) 學(xué) 號(hào): 姓 名: 選題名稱(chēng): 雙向鏈表選題難易級(jí)別:A級(jí)起止時(shí)間:2012年3月01日2012年4月07日指導(dǎo)教師: 目 錄 課題目標(biāo)1.1 程序功能簡(jiǎn)介1.2 課程設(shè)計(jì)要求1.3 評(píng)定難易級(jí)別具體實(shí)現(xiàn)2.1 程序總體方案2.2 改進(jìn)方案 改進(jìn)方案 具體實(shí)現(xiàn) 改進(jìn)方案 具體實(shí)現(xiàn)2.2.3 改進(jìn)三 改進(jìn)方案 具體實(shí)現(xiàn)三、 運(yùn)行結(jié)果一、課題目標(biāo)1.1 程序功能簡(jiǎn)介原程序定義了模版數(shù)據(jù)類(lèi)型的雙向鏈表類(lèi)型,并定義了鏈表的插入,刪除和輸出操作的成員函數(shù)。1.2 課

2、程設(shè)計(jì)要求(1)在原程序的基礎(chǔ)上擴(kuò)充雙向鏈表的功能,增加排序插入,根據(jù)數(shù)據(jù)查找結(jié)點(diǎn)及修改結(jié)點(diǎn)數(shù)據(jù)等功能。(2)將結(jié)點(diǎn)據(jù)數(shù)據(jù)改成通訊錄中的一個(gè)紀(jì)錄,增加年齡,姓名, 等數(shù)據(jù);并能根據(jù)姓名進(jìn)行向前或向后查找,鏈表根據(jù)姓名排序。(3)根據(jù)姓名查找記錄時(shí)支持通配符*和?,即*通配任意字符和字符串,?通配一個(gè)字符,字符不分大小寫(xiě)。(4)可以修改某個(gè)結(jié)點(diǎn),即修改其中的年齡和 字段,修改時(shí)新舊記錄要同時(shí)顯示在屏幕上,新紀(jì)錄按“確認(rèn)”鍵后才替代舊記錄,否則取消修改操作。(5)將通訊錄以文件的形式存在磁盤(pán)上,每次操作時(shí)將通訊錄調(diào)出,操作完畢后存盤(pán)。1.3 評(píng)定難易級(jí)別A級(jí)二、具體實(shí)現(xiàn)2.1 程序總體方案操作系統(tǒng)

3、:Windows XP結(jié) 束 改進(jìn)方案完成類(lèi)的封裝template class Node; template class DoubleLinkList; using namespace std;template class Nodefriend class DoubleLinkList; private :NodeType Data;Node *NextNode; Node *PreviousNode; public :Node();Node( NodeType &Value ); Node(); void show()tt年齡:Data.ageendl;/輸入節(jié)點(diǎn)數(shù)據(jù);temp

4、lateclass DoubleLinkListprivate : Node *FirstNode; Node *RearNode; public :DoubleLinkList(); DoubleLinkList(); bool IsEmpty(); void InsertAtFront(); void InsertAtRear(); void InsertAtMiddle(); bool RemoveFromFront(); bool RemoveFromRear(); bool RemoveFromMiddle(); void TraverseForwards(); void Trave

5、rseBackwards(); int LenghtOfDoubleLinkList(); void AddNode();/排序插入鏈表節(jié)點(diǎn)void DelByName();/根據(jù)姓名刪除節(jié)點(diǎn)void DelByIndex();/根據(jù)序號(hào)刪除節(jié)點(diǎn)int SearchName(char *name);/根據(jù)姓名查找節(jié)點(diǎn)bool UpdateByName(char *name);/根據(jù)姓名修改節(jié)點(diǎn)bool UpdateByIndex(int index);/根據(jù)序號(hào)修改節(jié)點(diǎn)bool LoadFromFile();/從文件中輸入數(shù)據(jù)bool SaveToFile();/將數(shù)據(jù)儲(chǔ)存進(jìn)文件bool co

6、mpstr(char *name,char *search1);/模糊比較Node *CreateNode(); void PrintList();void paixu(); 改進(jìn)方案主菜單具體化,使內(nèi)容更加詳盡完備。int main()DoubleLinkList List;int Option,i;char Name20;char str20;int option=0,index=0;coutttt 歡迎使用雙向鏈表通訊錄(鄢悅(1111250106)制作)endl;docouttttt 主菜單 endl;cout *endl;cout 1) 查看全部數(shù)據(jù)endl;cout

7、2) 刪除數(shù)據(jù)endl;cout 3) 添加數(shù)據(jù)(數(shù)據(jù)按姓名順序排列)endl;cout 4) 修改數(shù)據(jù)endl;cout 5) 查找數(shù)據(jù)endl;cout 6) 從文件中輸入數(shù)據(jù)endl;cout 7) 將數(shù)據(jù)輸出至文件并存盤(pán)endl;cout 8) 退出程序endl;coutOption;while(!cin)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候cin.clear();/清空輸入緩沖區(qū)cin.getline(str,20);/接收原輸入數(shù)據(jù)coutOption;/重新輸入switch(Option)case 1 :/查看全部數(shù)據(jù) do cout -endl; cout 1) 從前

8、往后查看全部數(shù)據(jù)endl; cout 2) 從后往前查看全部數(shù)據(jù)endl; cout 3) 返回主菜單endl; couti; while(!cin|(i4|i1)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候或超范圍 cin.clear();/清空輸入緩沖區(qū) cin.getline(str,20);/接收原輸入數(shù)據(jù) couti;/重新輸入 switch(i) case 1:List.TraverseForwards(); cin.get(); system(cls); break; case 2:List.TraverseBackwards(); cin.get(); system(cls)

9、; break; case 3:Option=3; cin.get(); system(cls); break; while(Option!=3); break;case 2 :/刪除數(shù)據(jù) do cout -endl; cout 1) 將數(shù)據(jù)從通訊錄頭刪除endl; cout 2) 將數(shù)據(jù)從通訊錄尾刪除endl; cout 3) 按序號(hào)刪除數(shù)據(jù)endl; cout 4) 按姓名刪除數(shù)據(jù)endl; cout 5) 返回主菜單endl; couti; while(!cin|(i5|i1)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候或超范圍 cin.clear();/清空輸入緩沖區(qū) cin.get

10、line(str,20);/接收原輸入數(shù)據(jù) couti;/重新輸入 switch(i) case 1:List.RemoveFromFront();/將數(shù)據(jù)從通訊錄頭刪除 cin.get(); coutn刪除后:nnendl; List.PrintList(); coutnn按任意鍵繼續(xù).endl; cin.get(); system(cls); break; case 2:List.RemoveFromRear();/將數(shù)據(jù)從通訊錄尾刪除 cin.get(); coutn刪除后:nnendl; List.PrintList(); coutnn按任意鍵繼續(xù).endl; cin.get(); s

11、ystem(cls); break; case 3: List.DelByIndex();/按序號(hào)刪除結(jié)點(diǎn) cin.get(); coutn刪除后:nnendl; List.PrintList(); coutnn按任意鍵繼續(xù).endl; cin.get(); system(cls); break; case 4: List.DelByName(); cin.get(); coutn刪除后:nnendl; List.PrintList(); coutnn按任意鍵繼續(xù).endl; cin.get(); system(cls); break; case 5: Option=5; system(cls

12、); break; while(Option!=5);/結(jié)束循環(huán),退回主菜單 break;case 3:/添加數(shù)據(jù)(按姓名順序排列) do cout -endl; cout 1) 將數(shù)據(jù)插入到通訊錄頭endl; cout 2) 將數(shù)據(jù)插入到通訊錄尾endl; cout 3) 將數(shù)據(jù)插入到通訊錄中間endl; cout 4) 排序插入數(shù)據(jù)endl; cout 5) 退回主菜單endl; couti; while(!cin|(i5|i1)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候或超范圍 cin.clear();/清空輸入緩沖區(qū) cin.getline(str,20);/接收原輸入數(shù)據(jù) cou

13、ti;/重新輸入 switch(i) case 1: coutnn; List.InsertAtFront();/將數(shù)據(jù)插入到通訊錄頭 List.PrintList(); coutnn按任意鍵繼續(xù).endl; getch(); system(cls); break; case 2: coutnn; List.InsertAtRear();/將結(jié)點(diǎn)插入到鏈表尾 List.PrintList(); coutnn按任意鍵繼續(xù).endl; getch(); system(cls); break; case 3: coutnn; List.InsertAtMiddle();/將結(jié)點(diǎn)插入到鏈表中間 Lis

14、t.PrintList(); coutnn按任意鍵繼續(xù).endl; getch(); system(cls); break; case 4: List.AddNode(); /排序插入鏈表結(jié)點(diǎn) List.PrintList(); coutnn按任意鍵繼續(xù).endl; getch(); system(cls); break; case 5: i=5; system(cls); break; while(i!=5); break;case 4 :/修改數(shù)據(jù) do cout -endl; cout 1) 按姓名修改endl; cout 2) 按序號(hào)修改endl; cout 3) 返回主菜單endl;

15、 couti; while(!cin|(i3|i1)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候或超范圍 cin.clear();/清空輸入緩沖區(qū) cin.getline(str,20);/接收原輸入數(shù)據(jù) couti;/重新輸入 switch(i) case 1: do i=List.LenghtOfDoubleLinkList(); coutName; cout 姓名為:Nameendl; coutstr; if(strlen(str)!=1|(str0!=Y&str0!=y) i=1; else i=0; while(i); List.UpdateByName(Name);/按姓名修改結(jié)

16、點(diǎn) break; case 2: do cout 通訊錄如下:n; i=List.LenghtOfDoubleLinkList(); coutindex; while(!cin)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候 cin.clear();/清空輸入緩沖區(qū) cin.getline(str,20);/接收原輸入數(shù)據(jù) coutindex;/重新輸入 coutt序號(hào)為:indexendl; coutstr; if(strlen(str)!=1|(str0!=Y&str0!=y) i=1; else if(iindex) cout 對(duì)不起,沒(méi)有這個(gè)序號(hào),請(qǐng)重新輸入endl; i=1; i=0

17、; while(i); List.UpdateByIndex(index);/按序號(hào)修改結(jié)點(diǎn) break; case 3: option=3; system(cls); break; while(option!=3);/結(jié)束循環(huán),退回主菜單 break;case 5 :/查找數(shù)據(jù) do cout -endl; cout 1) 按姓名查找endl; cout 2) 返回主菜單endl; couti; while(!cin|(i3|i1)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候或超范圍 cin.clear();/清空輸入緩沖區(qū) cin.getline(str,20);/接收原輸入數(shù)據(jù) cou

18、ti;/重新輸入 switch(i) case 1: do coutName; cout 姓名為:Nameendl; coutstr; if(strlen(str)!=1|(str0!=Y&str0!=y) i=1; else i=0; while(i); List.SearchName(Name);/按姓名查找通訊錄 coutnn按任意鍵繼續(xù).endl; cin.get(); system(cls); break; case 2:option=2; system(cls); break; while(option!=2);/結(jié)束循環(huán),退回主菜單 system(cls); break;case

19、 6:/從文件中輸入數(shù)據(jù)List.LoadFromFile();List.PrintList();coutnn按任意鍵繼續(xù).endl; cin.get(); system(cls); break;case 7 :/將數(shù)據(jù)輸出之文件并存盤(pán)List.SaveToFile();system(cls);break;case 8:break;default :coutstr;if(strlen(str)!=1|(str0!=Y&str0!=y) Option=1;else Option=8; while(Option!=8);/結(jié)束循環(huán),測(cè)試完成return 0;通配符的模糊匹配功能template/定

20、義通配符模糊匹配函數(shù)bool DoubleLinkList:compstr(char *name,char *search1)int i,l,l1;bool flag1,flag2;char name120;l1=strlen(name);strcpy(name1,name);for(i=0;i=A)&(namei=Z)name1i+=a-A;l=strlen(search1);if(l1l) return 0;for(i=0;il-1;i+)/關(guān)于*的模糊比較if(search1i!=name1i)break;if(search1i=*)flag1=true;elseflag1=false;

21、if(l1=l)/關(guān)于?的模糊比較for(i=0;il1;i+)if(search1i!=name1i&search1i!=?)break;if(il1) flag2=false;elseflag2=true;elseflag2=false;return (flag1|flag2);改將通訊錄以文件的形式存在磁盤(pán)上,每次操作時(shí)將通訊錄調(diào)出,操作完畢后存盤(pán)。bool DoubleLinkList:LoadFromFile()/從文件中調(diào)出通訊錄 Node *temp1,*temp2; ifstream infile; infile.open(A.txt,ios:in); if(!infile)

22、cout未找到文件!endl; return false; if(FirstNode!=NULL) coutnnt文件已經(jīng)打開(kāi)!nt若要重新打開(kāi),請(qǐng)關(guān)閉程序,重新運(yùn)行!nendl; cin.get(); coutnn已經(jīng)打開(kāi)的文件:endl; return false; while(!infile.eof() char temp= ; temp1=new Node; while(!(temp=a&temp=A&temp=a&temp=A&tempDn=temp; temp=infile.get(); n+; temp1-Dn=0; while(!(temp=0&

23、temp=0&tempData.telt=temp; temp=infile.get(); t+; temp1-Data.telt=0; while(!(temp=0&temp=0&tempData.age=a; if(FirstNode=NULL) FirstNode=temp1; RearNode=temp1; temp2=temp1; temp2-PreviousNode=NULL; else temp2-NextNode=temp1; temp1-PreviousNode=temp2; temp2=temp1; RearNode=temp1; temp1-NextNode=NULL;

24、RearNode=RearNode-PreviousNode;RearNode-NextNode=NULL;cin.get();infile.close();paixu(); return true; template/將數(shù)據(jù)存儲(chǔ)進(jìn)文件bool DoubleLinkList:SaveToFile()ofstream outfile;ifstream infile;char FileName20;coutn -endl;cout 請(qǐng)輸入文件名:;cin.get();cin.getline(FileName,20); outfile.open(FileName,ios:out);/以輸出的方式打開(kāi)

25、數(shù)據(jù)文件if(!outfile) /打開(kāi)文件錯(cuò)誤,輸出提示信息,退出程序cout 打開(kāi)文件錯(cuò)誤!endl;coutn 按任意鍵繼續(xù)endl;cout -endl;getch();return false;infile.open(FileName,ios:in);int i=0;while(i5)infile.get();if(infile.eof() outfile.setf(ios:left); outfile.width(20); outfile姓名; outfile.width(20); outfile 號(hào)碼; outfile.width(10); outfile年齡n; break;

26、i+; Node *CurrentNode=FirstNode; /定義結(jié)點(diǎn)指針while(CurrentNode) /當(dāng)指針沒(méi)有到鏈表尾結(jié)點(diǎn)時(shí) outfile.setf(ios:left); outfile.width(20);outfileD; outfile.width(20); outfileData.tel; outfile.width(10); outfileData.ageNextNode; /順著鏈表依次指向下一結(jié)點(diǎn)infile.close();outfile.close();cout 文件存儲(chǔ)完畢!endl;coutn 按任意鍵繼續(xù)endl;cout -end

27、l;getch();return true;各個(gè)函數(shù)的修改templatevoid DoubleLinkList:PrintList() coutnn通訊錄:n; if(FirstNode=NULL) couttt為空!n; cin.get(); return ; cout.setf(ios:left); cout.width(20); cout姓名; cout.width(20); cout 號(hào)碼; cout.width(10); cout年齡n; Node*p=FirstNode; while(p!=NULL) cout.setf(ios:left); cout.width(20);cou

28、tD; cout.width(20); coutData.tel; cout.width(10); coutData.ageNextNode; templatevoid DoubleLinkList:paixu() Node *p,*q,*t,*r; q=t=FirstNode; r=RearNode; int i=0,length=LenghtOfDoubleLinkList(); while(iNextNode!=NULL&jNextNode; if(strcmp(q-D,t-D)0) if(q!=FirstNode) q-PreviousN

29、ode-NextNode=t; else FirstNode=t; if(t!=RearNode) t-NextNode-PreviousNode=q; else RearNode=q; q-NextNode=t-NextNode; t-NextNode=q; t-PreviousNode=q-PreviousNode; q-PreviousNode=t; else q=q-NextNode; j+; i+; void DoubleLinkList:AddNode() InsertAtFront(); paixu(); /*/templatevoid DoubleLinkList:DelByN

30、ame() char Name20; cin.get(); cout 請(qǐng)輸入姓名:; cin.getline(Name,20); cout 姓名為:Nameendl; cout 確認(rèn)嗎?Y/N:; char t=cin.get(); while(t!=Y&t!=y&t!=n&t!=N) cin.get(); coutnn 非法輸入! 請(qǐng)輸入(Y/N):; t=cin.get(); switch(t) case Y: case y: break; case N: case n: return; Node *p,*q,*n; int i; int m=LenghtOfDoubleLinkList(

31、); p=q=FirstNode; coutnn 刪除了:nendl; i=SearchName(Name);if(i=1) RemoveFromFront(); return ; else if(i=t) RemoveFromRear(); return; else Node *p=FirstNode,*q,*t; for(int j=1;jNextNode; q=p-PreviousNode; t=p-NextNode; q-NextNode=t; t-PreviousNode=q; delete p; /*/templatevoid DoubleLinkList:DelByIndex()

32、 int i=LenghtOfDoubleLinkList(); int index; cin.get(); cout 該通訊錄的數(shù)據(jù)個(gè)數(shù):iendl; coutindex; while(!cin)/當(dāng)輸入的數(shù)據(jù)類(lèi)型與定義的變量類(lèi)型不一致的時(shí)候 coutindex;/重新輸入 while(indexi|index=0) coutnn 對(duì)不起,沒(méi)有這個(gè)序號(hào),請(qǐng)重新輸入: index; coutt確認(rèn)嗎?Y/N(輸入非Y按N算); cin.get(); char t=cin.get(); while(t!=Y&t!=y&t!=n&t!=N) cin.get(); coutnn 非法輸入! 請(qǐng)輸入(

33、Y/N):; t=cin.get(); switch(t) case Y: case y: break; case N: case n: return; if(index=1) RemoveFromFront(); return ; else if(i=index) RemoveFromRear(); return; else Node *p=FirstNode,*q,*t; for(int j=1;jNextNode; q=p-PreviousNode; t=p-NextNode; q-NextNode=t; t-PreviousNode=q; delete p; /*/templateint DoubleLinkList:SearchName(char *name) int i=1; int length=LenghtOfDoubleLinkList(); Node *p=FirstNode; if(IsEmpty() coutnt e

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論