編制一個演示單鏈表插入、刪除、查找等操作的程序_第1頁
編制一個演示單鏈表插入、刪除、查找等操作的程序_第2頁
編制一個演示單鏈表插入、刪除、查找等操作的程序_第3頁
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡介

1、實驗報告實驗名稱:編制一個演示單鏈表插入、刪除、查找等操作的程序班級: 信管131 姓名: 學(xué)號: 同實驗者: 實驗時間: 2014.10.10 成績: 指導(dǎo)老師: 實驗?zāi)康模航⒁粋€帶頭結(jié)點的單鏈表,結(jié)點的值域為整型數(shù)據(jù)。要求將用戶輸入的數(shù)據(jù)將頭插改成尾插。一、實驗設(shè)備及主要內(nèi)容一 一 實驗題目:建立線性鏈表用戶輸入的數(shù)據(jù)按尾插入法來建立相應(yīng)單鏈表2需求分析 本演示程序在VC環(huán)境下編寫,單鏈表的結(jié)點結(jié)構(gòu)除數(shù)據(jù)域外,還含有一個指針域。用C語言描述結(jié)點結(jié)構(gòu)如下: typedef int elemtype;typedef struct node elemtype data; /數(shù)據(jù)域 struct

2、 node *next; /指針域 linklist; 注意結(jié)點的建立方法及構(gòu)造新結(jié)點時指針的變化。構(gòu)造一個結(jié)點需用到C語言的標(biāo)準(zhǔn)函數(shù)malloc(),如給指針變量p分配一個結(jié)點的地址:p=(linklist *)malloc(sizeof(linklist);該語句的功能是申請分配一個類型為linklist的結(jié)點的地址空間,并將首地址存入指針變量p中。當(dāng)結(jié)點不需要時可以用標(biāo)準(zhǔn)函數(shù)free(p)釋放結(jié)點存儲空間,這時p為空值(NULL)測試數(shù)據(jù):輸入長度:5輸入數(shù)據(jù):10 11 12 13 14 15應(yīng)該輸出:15 14 13 12 11 103概要設(shè)計1 為了實現(xiàn)上述功能,需要對原程序進(jìn)行修

3、改【參考程序】/ 頭文件linklist.h的內(nèi)容: #include#includetypedef int elemtype;typedef struct node elemtype data; struct node *next; linklist; / 以下是主程序:#includelinklist.hlinklist *creatlist(int n) int x,k; linklist *head, *r, *p; p=(linklist *)malloc(sizeof(linklist); head=p; p-next=NULL; r=p; for(k=1;kdata=x; p-n

4、ext=NULL; r-next=p; r=r-next; return(head);void main() linklist *head,*p,a; int n; printf(input the length of the list:n); scanf(%d,&n); head=&a; head=creatlist(n); printf(output the list:n); p=head-next; while(p) printf(%d ,p-data); p=p-next; 主函數(shù)main()插入函數(shù):creatlist詳細(xì)設(shè)計:結(jié)構(gòu)節(jié)點:typedef int elemtype;ty

5、pedef struct node elemtype data; struct node *next; linklist;調(diào)試分析:輸入:10 11 12 13 14 15看結(jié)果是否是 15 14 13 12 11 10#include#include#includetypedef int elemtype;typedef struct node elemtype data; struct node *next; linklist;#includelinklist.hlinklist *creatlist(int n) int x,k; linklist *head, *r, *p; p=(l

6、inklist *)malloc(sizeof(linklist); head=p; p-next=NULL; r=p; for(k=1;kdata=x; p-next=head-next; head-next=p; r=p-next; return(head);void main() linklist *head,*p,a; int n; printf(input the length of the list:n); scanf(%d,&n); head=&a; head=creatlist(n); printf(output the list:n); p=head-next; while(p) printf(%d ,p-data)

溫馨提示

  • 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

提交評論