數(shù)據(jù)結(jié)構(gòu)順序存儲結(jié)構(gòu)C++實現(xiàn)_第1頁
數(shù)據(jù)結(jié)構(gòu)順序存儲結(jié)構(gòu)C++實現(xiàn)_第2頁
數(shù)據(jù)結(jié)構(gòu)順序存儲結(jié)構(gòu)C++實現(xiàn)_第3頁
數(shù)據(jù)結(jié)構(gòu)順序存儲結(jié)構(gòu)C++實現(xiàn)_第4頁
數(shù)據(jù)結(jié)構(gòu)順序存儲結(jié)構(gòu)C++實現(xiàn)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、.PAGE . 數(shù)據(jù)構(gòu)造實驗報告實驗?zāi)康氖炀氄莆站€性表的順序存儲構(gòu)造、鏈?zhǔn)酱鎯?gòu)造,并分別實現(xiàn)線性表的根本操作。熟練掌握順序存儲構(gòu)造中算法的實現(xiàn)。培養(yǎng)編程和上機(jī)調(diào)試能力。實驗容建立含有假設(shè)干元素的順序表,并實現(xiàn)插入、刪除、修改、查找等根本操作。并在屏幕上輸出。建立含有假設(shè)干元素的鏈?zhǔn)奖恚崿F(xiàn)插入、刪除、修改、查找等根本操作。并在屏幕上輸出。實驗步驟翻開VC6.0,新建文件。編寫代碼,運(yùn)行、調(diào)試、輸出結(jié)果。實驗代碼順序表#include #define elemtype intconst int ma*size=1000;class sequenlistprotected:elemtype a

2、ma*size;int len;public:void setnull()len=0;void input(int n)for(int j=1;jaj;len=n;void print()for(int i=1;i=len;i+)coutai ;coutendl;void length() cout現(xiàn)表長度len=ma*size-1)coutoverflowendl;else if(ilen+1)coutposition is not correct!=i;j-)aj+1=aj;ai=*;len+;void deletel(int i)int j;if(ilen)coutposition is

3、 not correct!endl;elsefor(j=i+1;j=len;j+)aj-1=aj;len-;int locate(elemtype *)int j=1;while(j=len)&(aj!=*)j+;if(j=len)return j;elsereturn 0;void change(elemtype *,elemtype y)int j;for(j=1;j=len;j+)if(aj=*)aj=y;void main()sequenlist L;elemtype *,y;int n,j;L.setnull();coutn;cout請輸入n個元素,建立順序表endl;L.input

4、(n);L.print();L.length;cout*j;L.insert(*,j);L.print();coutj;L.deletel(j);L.print();L.length;cout*;j=L.locate(*);if(j!=0)cout*在第j個位置;else cout找不到;coutendl;L.print();cout*;couty;L.change(*,y);L.print();鏈?zhǔn)奖恚?include #define elemtype intclass linkpublic:elemtype data;link *ne*t;class linklistprotected:l

5、ink *head;public:link *hcreat()link *s,*p;elemtype i;couti;p=new link;p-ne*t=NULL;while(i)s=new link;s-data=i;s-ne*t=p-ne*t;p-ne*t=s;cini;return p;void print (link *head)link *p;p=head-ne*t;while(p-ne*t!=NULL)coutdata;p=p-ne*t;coutdata;coutne*t;while(p!=NULL)&(p-data!=*)p=p-ne*t;return p;void delete

6、l(link *head,elemtype *)link *p,*q;q=head;p=head-ne*t;while(p!=NULL)&(p-data!=*)q=p;p=p-ne*t;if(p=NULL)coutne*t=p-ne*t;delete(p);void insert(link *head,elemtype *,elemtype y)link *p,*s;s=new link;s-data=y;if(head-ne*t=NULL)head-ne*t=s;s-ne*t=NULL;p=Locate(head,*);if(p=NULL)coutne*t=p-ne*t;p-ne*t=s;v

7、oid change(link *p,elemtype *,elemtype y)link *q;q=p-ne*t;while(q!=NULL)if(q-data=*)q-data=y;q=q-ne*t;int count(link *h)link *p;int n=0;p=h-ne*t;while(p!=NULL)n+;p=p-ne*t;return n;void main()int n;elemtype *,y;link *p,*q;linklist a;p=a.hcreat();a.print(p);couty;a.deletel(p,y);a.print(p);cout*;couty;a.insert(p,*,y);a.print(p);cout*y;a.change(p,*,y);a.print(p)

溫馨提示

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

評論

0/150

提交評論