![《線性表的順序存儲》實驗報告_第1頁](http://file4.renrendoc.com/view/45108ab307df13e6de373bc27749a609/45108ab307df13e6de373bc27749a6091.gif)
![《線性表的順序存儲》實驗報告_第2頁](http://file4.renrendoc.com/view/45108ab307df13e6de373bc27749a609/45108ab307df13e6de373bc27749a6092.gif)
![《線性表的順序存儲》實驗報告_第3頁](http://file4.renrendoc.com/view/45108ab307df13e6de373bc27749a609/45108ab307df13e6de373bc27749a6093.gif)
![《線性表的順序存儲》實驗報告_第4頁](http://file4.renrendoc.com/view/45108ab307df13e6de373bc27749a609/45108ab307df13e6de373bc27749a6094.gif)
![《線性表的順序存儲》實驗報告_第5頁](http://file4.renrendoc.com/view/45108ab307df13e6de373bc27749a609/45108ab307df13e6de373bc27749a6095.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
需解決的的問題利用順序表,設計一組輸入數(shù)據(jù)。數(shù)據(jù)結構的定義typedefstruct{ElemType*elem;intlength;intlistsize;}SqList;程序的結構圖函數(shù)的功能初始化一個空順序表voidInitSqList(SqList*L){L->elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));if(!L->elem)exit(OVERFLOW);L->length=0;L->listsize=LIST_INIT_SIZE;}輸入元素voidPushSqList(SqList*L){inti;printf("inputthelengthofthelist:");scanf("%d",&L->length);printf("inputthesqlist:");for(i=0;i<L->length;i++){printf("inputthe%dthnumber:",i+1);scanf("%d",&L->elem);}}在指定位置插入一個指定的元素voidInsertSqList(SqList*L,inti,ElemTypex){ElemType*newbase;intn,m;if(i<1||i>L->length+1){printf("ERROR!");}if(L->length>=L->listsize){newbase=(ElemType*)realloc(L->elem,(L->listsize+LISTINCREMENT)*sizeof(ElemType));if(!newbase)exit(OVERFLOW);L->elem=newbase;L->listsize+=LISTINCREMENT;}else{for(n=L->length;n>=i;n--){++L->length;L->elem[n]=L->elem[n-1];}L->elem[i-1]=x;printf("thelistis:");for(m=0;m<L->length+1;n++)printf("%d",L->elem[n]);}刪除指定位置的元素voidDelSqList(SqList*L,inti){ElemType*p,*q;ElemTypex;intn;if(i<1||i>L->length)printf("ERROR!");p=&(L->elem[i-1]);x=*p;for(q=p;q<&(L->elem[L->length-1]);q++)*q=*(q+1);L->length--;printf("theelementwhichisdeleteis%d",x);printf("thelistis:");for(n=0;n<L->length-1;n++)printf("%d",L->elem[n]);}將順序表中所有的元素顛倒voidChangeoverSqList(SqList*L){SqListS;inti,j;if(L->length==L->listsize)S.elem=(ElemType*)malloc(L->length*sizeof(ElemType));if(!S.elem)exit(OVERFLOW);else{for(i=0;i<L->length;i++)S.elem[i]=L->elem[L->length-i-1];for(i=0;i<L->length;i++)L->elem[i]=S.elem[i];}printf("thelistis:");for(j=0;j<L->length;i++)printf("%d",L->elem[i]);}按順序輸出表中元素voidPrintSqList(SqList*L){inti;for(i=0;i<L->length;i++)printf("%d",L->elem[i]);}摧毀順序表
voidDestroySqList(SqList*L){if(L->elem)free(L->elem);}清空順序表voidClearSqList(SqList*L){L->length=0;}查找指定位置的元素,并返回該元素的值intGetElem(SqList*L,inti){ElemTypex;if(i<1||i>L->length+1){printf("ERROR!");}else{x=L->elem[i-1];printf("theelemis%d",x);}}5?輸入/輸出數(shù)據(jù)1)創(chuàng)建一個順序表,先輸入表長度,然后輸入數(shù)據(jù)creatinput:inputinputinputinputinputacreatinput:inputinputinputinputinputasqlistFirstthethethethethethelengthofthelist:5sqlist=inputtheitlinumber2th3th4th5thnumber=2number=3numbei?:4numbep:522)選擇菜單,進行不同操作choosewhattodo:1.1nsertoneeLementintotheListDeleteoneeLementoftheListChangeouertheList4.outputtheeLementsoftheListDestroytheListEmptytheListGetthenu.mbei*oftheelementsoFthelistGettheeLementbyseapchinqitslacatian9.exitthemenu.inputthenunber-whichyouchoose選‘1’,在指定位置插入指定元素inputthenumbepwhichyouchoose1inputtheLocation選‘2’,刪除指定位置的元素inputthenumbepwhichyouclioose2inputthelocation選‘3’,顛倒順序表中元素的順序選‘4’,按順序輸出表中的元素選‘5’,摧毀順序表選‘6’,清空線性表選‘7’,輸出當前順序表的長度chooseuhattodo:1.1nsertoneeLementintothelistDeleteoneeLementoftheListChangeouepthelist4.outputtheelements:ofthelist5.DestroytheList6-EmptytheList7.Getthenu.nkber-oftheeleinentsofthelist.Gettheelenentbys&archinsiitslocation.exitthemenu.inputthenu.mbepuhichyouchoose7thenumberofth
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2023三年級英語上冊 Module 1 Getting to know you Unit 3 Are you Kitty說課稿 牛津滬教版(三起)
- 21《古詩三首》說課稿-2024-2025學年語文四年級上冊統(tǒng)編版001
- 6《摸一摸》說課稿-2024-2025學年科學一年級上冊青島版
- 2024-2025學年高中生物 第3章 植物的激素調節(jié) 第1節(jié) 植物生長素的發(fā)現(xiàn)說課稿 新人教版必修3001
- 2024年五年級英語下冊 Module 7 Unit 2 I will be home at seven oclock說課稿 外研版(三起)
- 2025住宅裝修物業(yè)管理合同(合同范本)
- 8《池子與河流》(說課稿)-2023-2024學年統(tǒng)編版語文三年級下冊
- 2025鍋爐拆除安全施工合同
- 2025有關電梯廣告的合同范本
- Unit 6 Disaster and Hope Understanding ideas 說課稿-2023-2024學年外研版高中英語(2019)必修第三冊
- 2024年農村述職報告
- 2025-2030年中國減肥連鎖市場發(fā)展前景調研及投資戰(zhàn)略分析報告
- 2024年湖南司法警官職業(yè)學院高職單招職業(yè)技能測驗歷年參考題庫(頻考版)含答案解析
- 女性私密項目培訓
- 2025年麗水龍泉市招商局招考招商引資工作人員高頻重點提升(共500題)附帶答案詳解
- 《加拿大概況》課件
- 期末復習之一般疑問句、否定句、特殊疑問句練習(畫線部分提問)(無答案)人教版(2024)七年級英語上冊
- TD-T 1048-2016耕作層土壤剝離利用技術規(guī)范
- 抖音賬號租賃合同協(xié)議
- 2024年高考真題-化學(重慶卷) 含解析
- 三甲醫(yī)院臨床試驗機構-31 V00 專業(yè)組備案及考核SOP
評論
0/150
提交評論