![線性表的基本操作實(shí)驗(yàn)報(bào)告_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/29/71736563-5b3c-4e44-884e-3f151ba8f047/71736563-5b3c-4e44-884e-3f151ba8f0471.gif)
![線性表的基本操作實(shí)驗(yàn)報(bào)告_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/29/71736563-5b3c-4e44-884e-3f151ba8f047/71736563-5b3c-4e44-884e-3f151ba8f0472.gif)
![線性表的基本操作實(shí)驗(yàn)報(bào)告_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/29/71736563-5b3c-4e44-884e-3f151ba8f047/71736563-5b3c-4e44-884e-3f151ba8f0473.gif)
![線性表的基本操作實(shí)驗(yàn)報(bào)告_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/29/71736563-5b3c-4e44-884e-3f151ba8f047/71736563-5b3c-4e44-884e-3f151ba8f0474.gif)
![線性表的基本操作實(shí)驗(yàn)報(bào)告_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-7/29/71736563-5b3c-4e44-884e-3f151ba8f047/71736563-5b3c-4e44-884e-3f151ba8f0475.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、線性表的基本操作實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)一:線性表的基本操作【實(shí)驗(yàn)?zāi)康摹繉W(xué)習(xí)掌握線性表的順序存儲結(jié)構(gòu)、鏈?zhǔn)酱鎯Y(jié)構(gòu)的設(shè)計(jì)與操作。對順序表建立、 插入、刪除的基本操作,對單鏈表建立、插入、刪除的基本操作算法。【實(shí)驗(yàn)內(nèi)容】1. 順序表的實(shí)踐1)建立4個(gè)元素的順序表s=sqlis t =1,2, 3, 4, 5,實(shí)現(xiàn)順序表建立的 基本操作。2)在sq 1 is t 二1, 2, 3, 4, 5的元素4與5之間插入一個(gè)元素9 ,實(shí)現(xiàn) 順序表插入的基本操作。3)在sql i st =1, 2, 3,4, 9, 5中刪除指定位置(i=5)上的元素9,實(shí)現(xiàn) 順序表的刪除的基本操作。2. 單鏈表的實(shí)踐3. 1)建立一個(gè)包
2、括頭結(jié)點(diǎn)與4個(gè)結(jié)點(diǎn)的(5,4, 2,1)的單鏈表,實(shí)現(xiàn)單鏈表建 立的基本操作。2)將該單鏈表的所有元素顯示出來。3)在已建好的單鏈表中的指定位置(i=3)插入一個(gè)結(jié)點(diǎn)3,實(shí)現(xiàn)單鏈表插 入的基本操作。4)在一個(gè)包括頭結(jié)點(diǎn)與5個(gè)結(jié)點(diǎn)的(5, 4, 3, 2, 1)的單鏈表的指定位置(如i =2)刪除一個(gè)結(jié)點(diǎn),實(shí)現(xiàn)單鏈表刪除的基本操作。5)實(shí)現(xiàn)單鏈表的求表長操作?!緦?shí)驗(yàn)步驟】1、打開VC+。2、建立工程:點(diǎn)F i le-Ne w,選Pr o j e c t標(biāo)簽,在列表中選Win32 Co ns ole Appli c at ion,再在右邊的框里為工程起好名字,選好路徑,點(diǎn)0K -fi ni sho
3、至此工程建立完畢。3 .創(chuàng)建源文件或頭文件:點(diǎn)File-Ne w,選F ile標(biāo)簽,在列表里選C+ S ource Fi 1 e。給文件起好名字,選好路徑,點(diǎn)0K。至此一個(gè)源文件就被添加到了剛創(chuàng)建的工程之中。4.寫好代碼 5 編譯-鏈接-調(diào)試1% #in c lude s t di o . h H # in clud e mallocx h #def ine OK 1 #de fine OVERFLOW -2 ftdefine ERROR 0100# d efine LIST IN IT SIZE#defin e LIST INCREMENT10t y pede f int E 1 e m T
4、 y pe;t yped e fint S t atus;t y p edefdE 1 emType*elem;length;竝nt1 i stsi z e;Stat u s Ini t L i st (SqList &L “in t i, n;L、elem = (ElemType*) m a Hoc (LIST_ INIT_S I ZE*sizeof (ElemType);i f (!L e 1 em) ret u r n(O VERFLOW);printfC輸入元素的個(gè)數(shù):);sc a nf (*%d ,&n):printfC輸入各元素的值:);f or( i =0;i li s t si
5、ze = LI S T.INI T.SIZE;re t urn 0 K ;S t atus List I n ser t (S q Lis t &L, int i E lemType e) E 1 emTy p e *newb a s e, *p, *q;if ( i = L. 1 i s ts i ze) ne wb a se = (E 1 emType *) r ea 1 loc (L elem, (L. lis t s i ze+L 1ST INCREMEN T)* sizeof (E lemType);if (Jnewbase) return (OVE RFLOW);L. el e m
6、 = newbas e ;L、1 is t size += LIST I NCREMENT;q = &(L、elem i - 1 );for (p =& (L. elemL. 1 e ng t h-1); p = q; p)*(p+l) =*p;*a = e ;+L length;return OK;Stat u s ListD e let e (S q L ist&L,i n t i, E 1 emTy p e &e) E 1 emTy p e * P , * q ;ftif ( i L、len g t h) r eturn ERROR;p = & (L、el e m i -1):e = *
7、P;q = L elem+L lengthT;f or (+p; p = q; +p)*(p 1 ) = *p;L- len g th;retur n OK;voi d VisitList(SqL i st L) in t i ;for(i=0;i leng t h; i+)p rintf ( % d t , L、el e mi);void main ()in t i, e;SqList L;Init L i s t (L);Vi s itList(L);P rintfC輸入插入位置與值:); scanf (*% d , %d, & i, &e);prin t f (插入元素后,表中的值:);
8、Lis tin s ert(L, i , e);Visit L i s t(L);print f (T輸入刪除位置:”);scanf (*%d ,& i );prin tfC刪除元素后,表中的值:);List Dele te (L, i , e);V is i t Li s t (L);2、#in c 1 ude stdio、h#include mallo c、h # def i ne O K 1#d efine OVERFLOW -210010#define L I S T_INIT_SIZE#def i n e LISTINCREMEN Tt yp e defi nt ElemTy p e
9、 ;typed ef int S t a tus;type def struct E 1 emTyp eintin t S qList;* e lem;1 engt h ;1 istsize;St a tus InitL i st( SqLi s t &L )int i, n;SIZE*sizeof (ElL elem = (E 1 emType*) malloc (LIST_I NIT emTyp e);i f (!L、elem) retu rn (OVERFLOW);P r intfC輸入元素的個(gè)數(shù):);s canf (%d, &n);print f(*輸入各元素的值:”);f or(i=
10、0 ;i 1 e ngth = n ;L、1 ists i ze = LIST_ I NI T_SI ZE;re t urn OK;v o id Visi t List (SqList L) int i;for(i=0;iLx leng t h; i +)pri n t f (%dt, L、el e mi);void main()SqL i s t L;I n i t List (L);VisitL i st(L);3、ftinclude std i o、h#incl u d e M malloc. h# d e f ine OK 1# define OVERFLOW 一2# d efine
11、ERR OROt yp e def i nt Sta t u s;t y p e d e f int El e mType;typedefstr u c t LNode El e mType d at a ;stru c t LNode *ne x t; LNod e,*Li nkList ;Status Li s tlnse r t (Lin kList & L, int i, Elem T ype e ) LinkList p, s;int j;P=L;j =0;wh i 1 e (p& jn e xt;+j;if(!p| |j i ) return ERROR;s= (LinkList)
12、 mal 1 oc(sizeo f (LNode);s-d a t a=e;s n e xt=p-next:p- n e xt = s ;r etu r n OK;Status ListDelete (Lin k L i s t &L, int i, El e m T y p e &e) Lin k Li st p, q;i nt j;p 二 L;j = O;while (p-n e xt&j Vil)p= p next;+j;if (! (p-ne x t) | | j i -1) r e tur n ERROR;q =p- n e x t; p - n e xt=q-nex t;e=q-
13、data;free(q);return 0K;Sta t us Crea t e L i st (LinkLi s t &L, int n) i nt i;L i nkLis t p;L = (LinkLi s t) ma 1 1 o c (siz e o f (LNode);L-n e xt = NUL L ;print f(H輸入元素的個(gè)數(shù)與相應(yīng)值:);sc a nf (% d , & n);for (i = n; i 0; i) p = (Link L i s t) ma 1 1 oc (si zeo f (LNode); 生成新結(jié)點(diǎn)3 scanf(%d, &p data);輸入指針p指
14、出匸n時(shí)所對應(yīng)的數(shù)值p-next = L next;L n e x t = p;return O K;v o id Vi s itList (Li n kLis t L)LNode * p ;p=Lnext;wh ile(p)printf (% d t, p-data);p=p nex t ;vo i d main() int i , n;L inkL i st L;ElemT y pe e;C rea t e L i s t (L, n);Vis itL i s t (L);print f (輸入插入位置與值:);scanf (%d, %d, &i, &e);printf C插入元素后,表中的值:);Lis tlnsert (L, i , e);Vis i tList(L);printf (H輸入刪除位置:);sc a nf ( % d &i);pr i ntf C刪除元素后,表中的值:);L is t D e 1 e t e (L, i , e);V i sitLi s t (L);【實(shí)驗(yàn)心得】今天就是本學(xué)期的第一次上機(jī)實(shí)驗(yàn)課,老師先給我們發(fā)了本次上機(jī)的內(nèi)
溫馨提示
- 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 教育培訓(xùn)合作委托居間合同
- 品牌營銷推廣策略指南
- 技術(shù)產(chǎn)品銷售合同
- 華為勞動合同管理制度
- 遺傳基因技術(shù)服務(wù)合同
- 外貿(mào)實(shí)務(wù)操作作業(yè)指導(dǎo)書
- 倉儲配送合同
- 智能工廠建設(shè)與運(yùn)營作業(yè)指導(dǎo)書
- 2025年來賓貨運(yùn)從業(yè)資格證模擬考試題庫
- 2025年陜西貨運(yùn)從業(yè)資格考試模擬考試題庫及答案大全
- 小學(xué)校本課程教材《趣味數(shù)學(xué)》
- 干細(xì)胞療法推廣方案
- (2024年)電工安全培訓(xùn)(新編)課件
- mil-std-1916抽樣標(biāo)準(zhǔn)(中文版)
- 城鄉(xiāng)環(huán)衛(wèi)一體化內(nèi)部管理制度
- 廣匯煤炭清潔煉化有限責(zé)任公司1000萬噸年煤炭分級提質(zhì)綜合利用項(xiàng)目變更環(huán)境影響報(bào)告書
- 小學(xué)數(shù)學(xué)六年級解方程練習(xí)300題及答案
- 大數(shù)據(jù)在化工行業(yè)中的應(yīng)用與創(chuàng)新
- 光伏十林業(yè)可行性報(bào)告
- 小學(xué)綜合實(shí)踐《我做環(huán)保宣傳員 保護(hù)環(huán)境人人有責(zé)》
- 鋼煤斗內(nèi)襯不銹鋼板施工工法
評論
0/150
提交評論