1、課程名稱:數(shù)據(jù)結(jié)構(gòu)與算法成績評定:實驗項目名稱:單鏈表的基本操作指導教師:學生姓名:沈麗桃學號: 10403080118 專業(yè)班級: 10 教育技術實驗項目類型:驗證實驗地點:科 b305 實驗時間: 2011 年 10 月 20 日一、實驗目的與要求:實驗目的: 實現(xiàn)線性鏈表的創(chuàng)建、查找、插入、刪除與輸出?;驹恚?單鏈表的基本操作二、實驗環(huán)境:(硬件環(huán)境、軟件環(huán)境)1.硬件環(huán)境:奔pc。2.軟件環(huán)境: windows xp 操作系統(tǒng), tc2.0 或 vc。三、實驗內(nèi)容:(原理、操作步驟、程序代碼等)#include #include #include struct celltype i
2、nt element; struct celltype*next; ; typedef int position; void main() struct celltype*head,*p; int x,choice; void insert(int x,struct celltype*p); void locate(int x,struct celltype*p); void delete(int x,struct celltype*p); p=(struct celltype*)malloc(sizeof(struct celltype); head=p; p-element=0; p-ne
3、xt=null; printf(“please option:1:insert 2:locate 3:deleten”); printf(“please choose:”); scanf(“%d ”,&choice); switch(choice) case 1: printf(“please input a node:”); scanf(“%d ”,&x); 湖南第一師范學院信息科學與工程系實驗報告 p=head; insert(x,p); for(p=head;p!=null;p=p-next) printf(“ %d ”,p-element); printf(“n ”);
4、 break; case 2: printf(“please input the data you want to locate:”); scanf(“%d ”,&x); p=head; locate(x,p); break; case 3: printf(“please input the data you want to delete:”); scanf(“%d ”,&x); delete(x,p); for(p=head;p!=null;p=p-next) printf(“%d ”,p-next); printf(“n ”); break; void insert(int
5、 x,struct celltype*p) struct celltype*t,*q; q=(struct celltype*)malloc(sizeof(struct celltype); q-next=x; while(xp-element)&(p!=null) t=p; p=p-next; if(xp-element)&(p-next!=null) p-next=q; q-next=null; else q-next=p; t-next=q; void locate(int x,struct celltype*p) while(p-next!=null) if(p-nex
6、t-element=x) printf(“the number %d is in %dn”,x,p); else printf(“the number not exist!n” ); void delete(int x,struct celltype*p) while(p-element!=x)&(p-next!=null) t=p; p=p-next; if(p-element=x) t-next=p-next error c2018:unknown character oxalerror c2065:please :undeclared identifier error c4024
7、:printf:different types for formal and actual parameter 1 error c4047: function: const*differs in levers of indirection from int error c2146:syntaxerror:missing) before identifieroption error c2017:illegal escape sequence error c2059:syntax error:) error c2143:syntax error:missing) before % 出現(xiàn)了很多錯誤,
8、主要是因為printf里的一對雙引號不是英文狀態(tài)下的。將雙引號改好后,錯誤消失,輸入時應注意細節(jié),最好直接在編譯環(huán)境下輸程序error c2043:illegal break error c2043:illegal case error c2198:scanf :too few actual parameters 這里是由于每一個case 間應有縮進,或者用大括號括起來。error c2065: t:undeclared identifier warning c4047:=: struct celltype*differs in levers of indirection 這個錯誤是p-next=x,應改為 p-element=x error c2223:left of-next must point to struct/union 這里是由于t 沒有定義,還有最后一個語句后沒有分號。四、實驗體會注意細節(jié),像拼寫錯誤就該避免,要注意所有符號必須是英文狀態(tài)下的。所有變量必須定義清楚,在用 switch 語句時,注意每個cas
評論
0/150
提交評論