鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)的基本操作-SuTree_第1頁(yè)
鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)的基本操作-SuTree_第2頁(yè)
鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)的基本操作-SuTree_第3頁(yè)
鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)的基本操作-SuTree_第4頁(yè)
鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)的基本操作-SuTree_第5頁(yè)
已閱讀5頁(yè),還剩1頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上廣州大學(xué)學(xué)生實(shí)驗(yàn)報(bào)告開課學(xué)院及實(shí)驗(yàn)室:計(jì)算機(jī)科學(xué)與工程實(shí)驗(yàn)室 2014年 4月28 日學(xué)院計(jì)算機(jī)科學(xué)與教育軟件學(xué)院年級(jí)、專業(yè)、班計(jì)機(jī)115姓名蘇權(quán)才學(xué)號(hào)實(shí)驗(yàn)課程名稱數(shù)據(jù)結(jié)構(gòu)成績(jī)實(shí)驗(yàn)項(xiàng)目名稱實(shí)驗(yàn)一 鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)的基本操作指導(dǎo)老師一、實(shí)驗(yàn)?zāi)康恼莆諉捂湵?,順序表,鏈?zhǔn)疥?duì)列的定義及基本操作二、使用儀器、器材微機(jī)一臺(tái)操作系統(tǒng):WinXP編程軟件:C+三、實(shí)驗(yàn)內(nèi)容及原理1、順序表和單鏈表的定義和操作及*L和L兩種接口變換;2、用*L和L接口實(shí)現(xiàn)隊(duì)列。四、實(shí)驗(yàn)過(guò)程原始數(shù)據(jù)記錄1、在list目錄下新建工程使用.h和.cpp文件,并編譯:2、將List1目錄改為用L*標(biāo)準(zhǔn)實(shí)現(xiàn)。將Lis

2、t2目錄改為用L標(biāo)準(zhǔn)實(shí)現(xiàn),并實(shí)現(xiàn)_union功能。1)、將List1目錄改為用L*標(biāo)準(zhǔn)實(shí)現(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+) /鏈表第一個(gè)節(jié)點(diǎn)存放頭節(jié)點(diǎn),開始節(jié)點(diǎn)從

7、一開始 GetElem(S, i, e); if (LocateElem(L, e)=0) ListInsert(L, L_len+1, e) ; 2)、將List2目錄改為用L標(biāo)準(zhǔn)實(shí)現(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、鏈?zhǔn)疥?duì)列的基本操作#include<iostream>#include<malloc.h>#include<conio.h>using namespace std;typedef struct node /定義連接隊(duì)列類型char data;struct

16、 node *link;QNode,*QLink;int EMPTYQLINK(QLink &front) /測(cè)試鏈接隊(duì)列是否為空return front=NULL;int ADDLINKQ(QLink &front,QLink &rear) /鏈接隊(duì)列的插入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) /鏈接隊(duì)列的刪除QLink p;if(EMPTYQLINK(front)return 0;p=front;front=p->link;free(p);return 1;char GETLINKQ(QLink &front) /取當(dāng)前隊(duì)頭元素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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論