軟件技術(shù)基礎(chǔ) 實(shí)驗(yàn)四:棧和隊(duì)列的操作實(shí)現(xiàn)_第1頁
軟件技術(shù)基礎(chǔ) 實(shí)驗(yàn)四:棧和隊(duì)列的操作實(shí)現(xiàn)_第2頁
軟件技術(shù)基礎(chǔ) 實(shí)驗(yàn)四:棧和隊(duì)列的操作實(shí)現(xiàn)_第3頁
軟件技術(shù)基礎(chǔ) 實(shí)驗(yàn)四:棧和隊(duì)列的操作實(shí)現(xiàn)_第4頁
軟件技術(shù)基礎(chǔ) 實(shí)驗(yàn)四:棧和隊(duì)列的操作實(shí)現(xiàn)_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、電子科技大學(xué) 電子工程 學(xué)院標(biāo) 準(zhǔn) 實(shí) 驗(yàn) 報(bào) 告(實(shí)驗(yàn))課程名稱 軟件技術(shù)基礎(chǔ) 學(xué)生姓名: 學(xué) 號: 指導(dǎo)教師:1、 實(shí)驗(yàn)名稱實(shí)驗(yàn)四:棧和隊(duì)列的操作實(shí)現(xiàn)二、實(shí)驗(yàn)?zāi)康睦斫鈼:完?duì)列的基本概念,棧和隊(duì)列操作的基本方法以及其編程實(shí)現(xiàn)。通過本實(shí)驗(yàn)的兩個(gè)項(xiàng)目的編程、調(diào)試和運(yùn)行結(jié)果的比較,分析棧和隊(duì)列的差別。三、實(shí)驗(yàn)內(nèi)容1、 設(shè)計(jì)一個(gè)容量為4的循環(huán)隊(duì)列,編程實(shí)現(xiàn)如下操作,并顯示各步驟操作后隊(duì)列的內(nèi)容:A、隊(duì)列初始化為空;B、將1、2、3三個(gè)數(shù)據(jù)依次做入隊(duì)操作;C、做兩次出隊(duì)操作(1、2出隊(duì));D、將4、5、6三個(gè)數(shù)據(jù)依次做入隊(duì)操作;E、將數(shù)據(jù)7做入隊(duì)操作;2、設(shè)計(jì)一個(gè)容量為4的順序棧,編程實(shí)現(xiàn)如下操作,并

2、顯示各步驟操作后棧的內(nèi)容:A、棧初始化為空;B、將1、2、3三個(gè)數(shù)據(jù)依次做入棧操作;C、做兩次出棧操作;D、將4、5、6三個(gè)數(shù)據(jù)依次做入棧操作;E、將數(shù)據(jù)7做入棧操作;4、 實(shí)驗(yàn)程序1.循環(huán)隊(duì)列程序#include<stdio.h>#include<malloc.h>#define true 1#define false 0#define maxnum 5typedef struct int datamaxnum; int front; int rear; queuetype;void main()void initiatequeue(queuetype *q);int

3、 enter(queuetype *q,int x);int deletequeue(queuetype *q);void printqueue(queuetype *q);queuetype *q; q=(queuetype*)malloc(sizeof(queuetype); initiatequeue(q); enter(q,1); enter(q,2); enter(q,3);printf("入隊(duì)操作后:n"); printqueue(q); printf("n兩次出隊(duì)操作后:n");deletequeue(q); deletequeue(q);

4、 printqueue(q); printf("n三次入隊(duì)操作后:n"); enter(q,4); enter(q,5); enter(q,6); printqueue(q); printf("n第四次入隊(duì)操作后:n"); enter(q,7);void initiatequeue(queuetype *q)/初始化隊(duì)列q->front=q->rear=0;int enter(queuetype *q,int x)/入隊(duì)操作if(q->rear)+1)%maxnum=q->front)printf("隊(duì)列已滿,不能進(jìn)行入

5、隊(duì)操作n");return(false); elseq->rear=(q->rear+1)%maxnum;q->dataq->rear=x;printf("成功插入%dn",x);return(true);int deletequeue(queuetype *q)/出隊(duì)操作if(q->rear=q->front)printf("隊(duì)列已空n");return(false);else q->front=(q->front+1)%maxnum;printf("成功刪除n");retu

6、rn(q->dataq->front);void printqueue(queuetype *q)/輸出隊(duì)列 int l;if(q->front=q->rear)printf("隊(duì)列已空"); return;l=q->front;printf("結(jié)果是n");while(1) l=(+l)%maxnum; printf("%dn",q->datal);if(l=q->rear) break;2.順序棧程序#include<stdio.h>#include<malloc.h&g

7、t;#define true 1#define false 0#define maxnum 4typedef struct int datamaxnum; int top; stacktype;void main()void initiatestack(stacktype *s);int pushstack(stacktype *s,int x);int popstack(stacktype *s);int printstack(stacktype *s);stacktype *s;s=(stacktype*)malloc(sizeof(stacktype); initiatestack(s)

8、;printf("入棧操作后:n");pushstack(s,1);pushstack(s,2);pushstack(s,3);printstack(s);printf("n兩次出棧操作后:n");popstack(s);popstack(s);printstack(s);printf("n三次入棧操作后:n");pushstack(s,4);pushstack(s,5);pushstack(s,6);printstack(s);printf("n第四次入棧操作后:n");pushstack(s,7);void i

9、nitiatestack(stacktype *s)/初始化s->top=-1;int pushstack(stacktype *s,int x)/入棧操作if(s->top>=maxnum-1)printf("棧已滿,不能進(jìn)行入棧操作n");return(false);elses->top+;s->datas->top=x;return(true);int popstack(stacktype *s)/出棧操作if(s->top<0)printf("棧為空n");return(false);elseprintf("出棧成功n");s->top-;return(s->datas->top+1);int printstack(stacktype *s)/輸出int i;if(s->top<0)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論