線性表的基本操作實驗報告_第1頁
線性表的基本操作實驗報告_第2頁
線性表的基本操作實驗報告_第3頁
線性表的基本操作實驗報告_第4頁
線性表的基本操作實驗報告_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

實驗一 線性表的基本操作實驗一 線性表的基本操作 實驗目的實驗目的 學習掌握線性表的順序存儲結構 鏈式存儲結構的設計與操作 對順序表建立 學習掌握線性表的順序存儲結構 鏈式存儲結構的設計與操作 對順序表建立 插入 刪除的基本操作 對單鏈表建立 插入 刪除的基本操作算法 插入 刪除的基本操作 對單鏈表建立 插入 刪除的基本操作算法 實驗內(nèi)容實驗內(nèi)容 1 1 順序表的實踐順序表的實踐 1 1 建立建立 4 4 個元素的順序表個元素的順序表 s sqlist 1s sqlist 1 2 2 3 3 4 4 5 5 實現(xiàn)順序表建立 實現(xiàn)順序表建立 的基本操作 的基本操作 2 2 在在 sqlistsqlist 1 1 2 2 3 3 4 4 5 5 的元素的元素 4 4 和和 5 5 之間插入一個元素之間插入一個元素 9 9 實現(xiàn) 實現(xiàn) 順序表插入的基本操作 順序表插入的基本操作 3 3 在在 sqlistsqlist 1 1 2 2 3 3 4 4 9 9 5 5 中刪除指定位置 中刪除指定位置 i 5i 5 上的元素 上的元素 9 9 實現(xiàn)順序表的刪除的基本操作 實現(xiàn)順序表的刪除的基本操作 2 2 單鏈表的實踐單鏈表的實踐 3 3 1 1 建立一個包括頭結點和建立一個包括頭結點和 4 4 個結點的 個結點的 5 5 4 4 2 2 1 1 的單鏈表 實現(xiàn)單鏈 的單鏈表 實現(xiàn)單鏈 表建立的基本操作 表建立的基本操作 2 2 將該單鏈表的所有元素顯示出來 將該單鏈表的所有元素顯示出來 3 3 在已建好的單鏈表中的指定位置 在已建好的單鏈表中的指定位置 i 3i 3 插入一個結點 插入一個結點 3 3 實現(xiàn)單鏈表插 實現(xiàn)單鏈表插 入的基本操作 入的基本操作 4 4 在一個包括頭結點和在一個包括頭結點和 5 5 個結點的 個結點的 5 5 4 4 3 3 2 2 1 1 的單鏈表的指定位置 的單鏈表的指定位置 如 如 i 2i 2 刪除一個結點 實現(xiàn)單鏈表刪除的基本操作 刪除一個結點 實現(xiàn)單鏈表刪除的基本操作 5 5 實現(xiàn)單鏈表的求表長操作 實現(xiàn)單鏈表的求表長操作 實驗步驟實驗步驟 1 1 打開打開 VC VC 2 2 建立工程 點建立工程 點 File NewFile New 選 選 ProjectProject 標簽 在列表中選標簽 在列表中選 Win32Win32 ConsoleConsole ApplicationApplication 再在右邊的框里為工程起好名字 選好路徑 點 再在右邊的框里為工程起好名字 選好路徑 點 OK finishOK finish 至此工程建立完畢 至此工程建立完畢 3 3 創(chuàng)建源文件或頭文件 點創(chuàng)建源文件或頭文件 點 File NewFile New 選 選 FileFile 標簽 在列表里選標簽 在列表里選 C C SourceSource FileFile 給文件起好名字 選好路徑 點 給文件起好名字 選好路徑 點 OKOK 至此一個源文件就被添加到了剛創(chuàng) 至此一個源文件就被添加到了剛創(chuàng) 建的工程之中 建的工程之中 4 4 寫好代碼 寫好代碼 5 5 編譯 鏈接 調(diào)試 編譯 鏈接 調(diào)試 1 1 include include stdio h stdio h include include malloc h malloc h define define OKOK 1 1 define define OVERFLOWOVERFLOW 2 2 define define ERRORERROR 0 0 define define LIST INIT SIZELIST INIT SIZE 100100 define define LISTINCREMENTLISTINCREMENT 1010 typedeftypedef intint ElemType ElemType typedeftypedef intint Status Status typedeftypedef structstruct ElemTypeElemType elem elem intint length length intint listsize listsize SqList SqList StatusStatus InitList InitList SqListSqList i n L elemL elem ElemType ElemType mallocmalloc LIST INIT SIZE sizeof LIST INIT SIZE sizeof ElemType ElemType ifif L elem L elem return OVERFLOW return OVERFLOW printf printf 輸入元素的個數(shù)輸入元素的個數(shù) scanf d scanf d printf printf 輸入各元素的值輸入各元素的值 for i 0 i n i for i 0 i n i scanf d scanf d L lengthL length n n L listsizeL listsize LIST INIT SIZE LIST INIT SIZE returnreturn OK OK StatusStatus ListInsert SqListListInsert SqList newbase p q ifif i i L length 1 L length 1 returnreturn ERROR ERROR ifif L length L length L listsize L listsize newbasenewbase ElemType ElemType realloc L elem realloc L elem L listsize LISTINCREMENT sizeof L listsize LISTINCREMENT sizeof ElemType ElemType ifif newbase newbase return OVERFLOW return OVERFLOW L elemL elem newbase newbase L listsizeL listsize LISTINCREMENT LISTINCREMENT q q forfor p p p p q q p p p 1 p 1 p p q q e e L length L length returnreturn OK OK StatusStatus ListDelete SqListListDelete SqList p q if iif i L length L length returnreturn ERROR ERROR p p e e p p q q L elem L length 1 L elem L length 1 forfor p p p p q q p p p 1 p 1 p p L length L length returnreturn OK OK voidvoid VisitList SqListVisitList SqList L L intint i i for i 0 i L length i for i 0 i L length i printf d t L elem i printf d t L elem i voidvoid main main intint i e i e SqListSqList L L InitList L InitList L VisitList L VisitList L printf printf 輸入插入位置和值輸入插入位置和值 scanf d d scanf d d printf printf 插入元素后 表中的值插入元素后 表中的值 ListInsert L i e ListInsert L i e VisitList L VisitList L printf printf 輸入刪除位置輸入刪除位置 scanf d scanf d printf printf 刪除元素后 表中的值刪除元素后 表中的值 ListDelete L i e ListDelete L i e VisitList L VisitList L 2 2 include include stdio h stdio h include include malloc h malloc h define define OKOK 1 1 define define OVERFLOWOVERFLOW 2 2 define define LIST INIT SIZELIST INIT SIZE 100100 define define LISTINCREMENTLISTINCREMENT 1010 typedeftypedef intint ElemType ElemType typedeftypedef intint Status Status typedeftypedef structstruct ElemTypeElemType elem elem intint length length intint listsize listsize SqList SqList StatusStatus InitList InitList SqListSqList i n L elemL elem ElemType ElemType mallocmalloc LIST INIT SIZE sizeof LIST INIT SIZE sizeof ElemType ElemType ifif L elem L elem return OVERFLOW return OVERFLOW printf printf 輸入元素的個數(shù)輸入元素的個數(shù) scanf d scanf d printf printf 輸入各元素的值輸入各元素的值 for i 0 i n i for i 0 i n i scanf d scanf d L lengthL length n n L listsizeL listsize LIST INIT SIZE LIST INIT SIZE returnreturn OK OK voidvoid VisitList SqListVisitList SqList L L intint i i for i 0 i L length i for i 0 i L length i printf d t L elem i printf d t L elem i voidvoid main main SqListSqList L L InitList L InitList L VisitList L VisitList L 3 3 include include stdio h stdio h include include malloc h malloc h define define OKOK 1 1 define define OVERFLOWOVERFLOW 2 2 define define ERRORERROR 0 0 typedeftypedef intint Status Status typedeftypedef intint ElemType ElemType typedeftypedef structstruct LNodeLNode ElemTypeElemType data data structstruct LNodeLNode next next LNode LinkList LNode LinkList StatusStatus ListInsert LinkListListInsert LinkList p s intint j j p L j 0 p L j 0 while p j p p next j if p j i if p j i returnreturn ERROR ERROR s LinkList malloc sizeof LNode s LinkList malloc sizeof LNode s data e s data e s next p next s next p next p next s p next s returnreturn OK OK StatusStatus ListDelete LinkListListDelete LinkList p q intint j j p L j 0 p L j 0 while p next j p p next j if p next j i 1 if p next j i 1 returnreturn ERROR ERROR q p next p next q next q p next p next q next e q data free q e q data free q returnreturn OK OK StatusStatus CreateList LinkListCreateList LinkList i LinkListLinkList p p L L LinkList LinkList mallocmalloc sizeof sizeof LNode LNode L nextL next NULL NULL printf printf 輸入元素的個數(shù)和相應值 輸入元素的個數(shù)和相應值 scanf d scanf d forfor i i n n i i 0 0 i i p p LinkList LinkList mallocmalloc sizeof sizeof LNode LNode 生成新結點生成新結點 scanf d scanf d 輸入指針輸入指針 p p 指出指出 i ni n 時所對應的數(shù)值時所對應的數(shù)值 p nextp next L next L next L nextL next p p returnreturn OK OK voidvoid VisitList LinkListVisitList LinkList L L LNode LNode p p p L next p L next while p while p printf d t p data printf d t p data p p next p p next voidvoid main main intint i n i n LinkListLinkList L L ElemTypeElemType e e CreateList L n CreateList L n VisitList L VisitList L printf printf 輸入插入位置和值輸入插入位置和值 scanf d d scanf d d printf printf 插入元素后 表中的值插入元素后 表中的值 ListInsert L i e

溫馨提示

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

最新文檔

評論

0/150

提交評論