




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上廣州大學學生實驗報告開課學院及實驗室:計算機科學與工程實驗室 2014年 4月28 日學院計算機科學與教育軟件學院年級、專業(yè)、班計機115姓名蘇權(quán)才學號實驗課程名稱數(shù)據(jù)結(jié)構(gòu)成績實驗項目名稱實驗一 鏈式存儲結(jié)構(gòu)的基本操作指導老師一、實驗目的掌握單鏈表,順序表,鏈式隊列的定義及基本操作二、使用儀器、器材微機一臺操作系統(tǒng):WinXP編程軟件:C+三、實驗內(nèi)容及原理1、順序表和單鏈表的定義和操作及*L和L兩種接口變換;2、用*L和L接口實現(xiàn)隊列。四、實驗過程原始數(shù)據(jù)記錄1、在list目錄下新建工程使用.h和.cpp文件,并編譯:2、將List1目錄改為用L*標準實現(xiàn)。將Lis
2、t2目錄改為用L標準實現(xiàn),并實現(xiàn)_union功能。1)、將List1目錄改為用L*標準實現(xiàn)#include <iostream>using namespace std;# define maxsize 100typedef int ElemType;typedef structElemType datamaxsize; int length;SqList;void InitList(SqList *&L); int ListLength(SqList *L); int GetElem(SqList *L,int i,ElemType &e); int LocateE
3、lem(SqList *L,ElemType e); int ListInsert(SqList *&L,int i,ElemType e); /void InitList(SqList *&L) L=(SqList *)malloc(sizeof(SqList);L->length=0;int ListLength(SqList *L) return (L->length); int GetElem(SqList *L,int i,ElemType &e)if(i<1|i>L->length)return 0;e=L->datai-
4、1;return 1;int LocateElem(SqList *L,ElemType e)int i=0;while(i<L->length&&L->datai!=e)i+;if(i>=L->length)return 0;elsereturn i+1;int ListInsert(SqList *&L,int i,ElemType e)int j;if(i<1|i>L->length+1)return 0;i-;for(j=L->length;j>i;j-)L->dataj=L->dataj-
5、1;L->datai=e;L->length+;return 1;#include "list.h"void main()void _union(SqList *L, SqList *S);/ElemType e;SqList *La,*Lb;InitList(La); InitList(Lb); ListInsert(La,1,3); ListInsert(La,2,7);ListInsert(La,3,28); ListInsert(Lb,1,7);ListInsert(Lb,2,29);_union(La,Lb);cout<<"Lis
6、t A's elements:"for (int i=0;i<= ListLength(La)-1; i+)/if (GetElem(La, i, e)=1)cout<< La->datai<<" "cout<<endl;/ void _union(SqList *L, SqList *S) ElemType e; int L_len=ListLength(L); int S_len=ListLength(S); for(int i=1;i<= S_len;i+) /鏈表第一個節(jié)點存放頭節(jié)點,開始節(jié)點從
7、一開始 GetElem(S, i, e); if (LocateElem(L, e)=0) ListInsert(L, L_len+1, e) ; 2)、將List2目錄改為用L標準實現(xiàn)#include <iostream>using namespace std;# define maxsize 100typedef int ElemType;typedef structElemType datamaxsize; int length;SqList;void CreateList(SqList *&L,ElemType a,int n); void InitList(SqL
8、ist *&L); void DestroyList(SqList *&L); int ListEmpty(SqList *L); int ListLength(SqList *L); void DispList(SqList *L); int GetElem(SqList *L,int i,ElemType &e); int LocateElem(SqList *L,ElemType e); int ListInsert(SqList *&L,int i,ElemType e); int ListDelete(SqList *&L,int i,Elem
9、Type &e); /void CreateList(SqList *&L,ElemType a,int n)int i;L=(SqList *)malloc(sizeof(SqList);for(i=0;i<n;i+)L->datai=ai;L->length=n;void InitList(SqList *&L) L=(SqList *)malloc(sizeof(SqList);L->length=0;void DestroyList(SqList *&L) free(L);int ListEmpty(SqList *L) retu
10、rn (L->length=0);int ListLength(SqList *L) return (L->length); void DispList(SqList *L)int i;if(ListEmpty(L) return ;for(i=0;i<L->length;i+)cout<<" "<<L->datai;/cout<<endl;int GetElem(SqList *L,int i,ElemType &e)if(i<1|i>L->length)return 0;e=L-
11、>datai-1;return 1;int LocateElem(SqList *L,ElemType e)int i=0;while(i<L->length&&L->datai!=e)i+;if(i>=L->length)return 0;elsereturn i+1;int ListInsert(SqList *&L,int i,ElemType e)int j;if(i<1|i>L->length+1)return 0;i-;for(j=L->length;j>i;j-)L->dataj=L-
12、>dataj-1;L->datai=e;L->length+;return 1;int ListDelete(SqList *&L,int i,ElemType &e)int j;if(i<1|i>L->length)return 0;i-;e=L->datai;for(j=i;j<L->length-1;j+)L->dataj=L->dataj+1;L->length-;return 1;#include "List.h"void main()ElemType f,a1; ElemTy
13、pe data5='a','b','c','d','e'SqList *L;InitList(L);CreateList(L,data,5);cout<<"L's elememts: "DispList(L);cout<<endl;cout<<"L's length: "<<ListLength(L)<<endl;cout<<"Isn't empty table retu
14、rns (0): "<<ListEmpty(L)<<endl; GetElem(L,3,a1);cout<<"The value of the third element: "<<a1<<endl;cout<<"The position of a: "<<LocateElem(L,'a')<<endl;ListInsert(L,3,'f');cout<<"Insert element f in t
15、he fourth: "DispList(L);cout<<endl;ListDelete(L,4,f);cout<<"Delete elements of f:"DispList(L);cout<<endl;DestroyList(L);3、鏈式隊列的基本操作#include<iostream>#include<malloc.h>#include<conio.h>using namespace std;typedef struct node /定義連接隊列類型char data;struct
16、 node *link;QNode,*QLink;int EMPTYQLINK(QLink &front) /測試鏈接隊列是否為空return front=NULL;int ADDLINKQ(QLink &front,QLink &rear) /鏈接隊列的插入char item='n'QLink p;cout<<"n讀入用戶鍵入的字符:"while(item!='0')cin>>item;if(!(p=(QLink)malloc(sizeof(QNode)return 0;p->data=
17、item; p->link=NULL;if(front=NULL)front=p; elserear->link=p;rear=p;return 1;int DELLINKQ(QLink &front) /鏈接隊列的刪除QLink p;if(EMPTYQLINK(front)return 0;p=front;front=p->link;free(p);return 1;char GETLINKQ(QLink &front) /取當前隊頭元素char item;if(EMPTYQLINK(front)return 0;item=front->data;DE
18、LLINKQ(front);return item;void main()int choice;QLink front=NULL,rear=NULL;docout<<"X"while(!_kbhit();cout<<"鍵盤有輸入."choice=ADDLINKQ(front,rear);if(choice) cout<<"鍵入字符已保存至緩沖區(qū)."cout<<"n輸出緩沖區(qū)的字符:"while(choice)if(front!=rear) cout<<GETLINKQ(front
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年臺式離子風機合作協(xié)議書
- 2025四川省安全員考試題庫附答案
- 太原市城市更新問題及對策研究
- 《葉之音》系列作品沒骨法的實踐探索
- 知識產(chǎn)權(quán)商標轉(zhuǎn)讓居間合同
- 二零二五年度寶寶日托管與兒童安全防范教育合同
- 2025年會計、審計及稅務服務項目建議書
- 2025年自動化生產(chǎn)線成套裝備項目建議書
- 2025年8月鎮(zhèn)人大代表履職情況報告
- 臨床試驗數(shù)據(jù)分析外包行業(yè)深度調(diào)研及發(fā)展戰(zhàn)略咨詢報告
- DL∕T 5210.2-2018 電力建設施工質(zhì)量驗收規(guī)程 第2部分:鍋爐機組
- 電梯每月電梯安全調(diào)度
- 2024年部編版五年級下冊語文第一單元綜合檢測試卷及答案
- (新教材)青島版六三制四年級下冊科學全冊教案(含教學計劃)
- 部編2023版道德與法治六年級下冊活動園問題及答案
- 第18課 罐和壺(一)
- 初二下分式混合計算練習1(附答案)
- (完整版)振幅調(diào)制與解調(diào)習題及其解答
- 抗震支架施工安裝合同
- JJG 657-2019 呼出氣體酒精含量檢測儀 檢定規(guī)程(高清版)
- 政法書記在全縣公安工作會議上的講話
評論
0/150
提交評論