下载

1下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 实验二、栈和队列的应用

实验二、栈和队列的应用.doc

实验二、栈和队列的应用

我那个去
2012-05-15 0人阅读 举报 0 0 暂无简介

简介:本文档为《实验二、栈和队列的应用doc》,可适用于IT/计算机领域

实验二、栈和队列的应用一、实验目的、掌握栈的特点(先进后出FILO)及基本操作,如入栈、出栈等栈的顺序存储结构和链式存储结构以便在实际问题背景下灵活应用。、掌握队列的特点(先进先出FIFO)及基本操作,如入队、出队等队列顺序存储结构、链式存储结构和循环队列的实现以便在实际问题背景下灵活运用。二、实验内容.顺序栈的实现和运算.链栈的实现和运算.顺序队列的实现和运算.链式队列的实现和运算.循环队列的实现和运算三、实验要求.用CC完成算法设计和程序设计并上机调试通过。.撰写实验报告提供实验结果和数据。.分析算法要求给出具体的算法分析结果包括时间复杂度和空间复杂度并简要给出算法设计小结和心得。四、程序实现写出每个操作的算法(操作过程)源程序清单(供参考)程序:顺序栈的实现和运算#include<stdioh>#defineMAXNcharstackMAXNinttop=intpush(charx){if(top>=MAXN)return()stacktop=xreturn()}intpop(char*py){if(top==)return()*py=stacktopreturn()}voidmain(){inticharchx,chyprintf("inputthecharyouwanttopushn")scanf("c",chx)while(chx!='')if(push(chx)==)printf("failure!n")else{printf("success!n")printf("inputacharforchxtopushnchx=")getchar()scanf("c",chx)}i=while(stacki!=''){printf("c",stacki)i}if(pop(chy)==)printf("failure!n")else{printf("success!n")printf("Thepopchariscn",chy)}for(i=topi>=i)printf("c",stacki)}程序:链栈的实现和运算#include<stdioh>#include<malloch>structnode{chardatastructnode*link}typedefstructnodeNODENODE*top=voidpushl(charx){NODE*pp=(NODE*)malloc(sizeof(NODE))p>data=xp>link=toptop=p}intpopl(char*py){NODE*pif(top==)return()*py=top>datap=toptop=top>linkfree(p)return()}voidmain(){NODE*pcharchx,chyprintf("inputthecharyouwanttopushn")scanf("c",chx)while(chx!=''){pushl(chx)getchar()scanf("c",chx)}p=(NODE*)malloc(sizeof(NODE))p=topwhile(p!=){printf("c",p>data)p=p>link}printf("n")if(popl(chy)==)printf("failure!n")else{printf("success!n")printf("Thepopchariscn",chy)}p=(NODE*)malloc(sizeof(NODE))p=topwhile(p!=){printf("c",p>data)p=p>link}printf("n")}程序:顺序队列的实现和运算#include<stdioh>#defineMAXNcharqMAXNinthead=,tail=intenqueue(charx){if(tail==MAXN)return()qtail=xreturn()}intdequeue(char*py){if(head==tail)return()*py=qheadreturn()}voidmain(){inticharchx,chyprintf("inputthecharyouwanttoenqueuen")scanf("c",chx)while(chx!='')if(enqueue(chx)==)printf("failure!n")else{printf("success!n")printf("inputacharforchxtoenqueuenchx=")getchar()scanf("c",chx)}i=while(qi!=''){printf("c",qi)i}if(dequeue(chy)==)printf("failure!n")else{printf("success!n")printf("Thedequeuechariscn",chy)}for(i=headi<=taili)printf("c",qi)}程序:链式队列的实现和运算#include<stdioh>#include<malloch>"structnode{chardatastructnode*link}typedefstructnodeNODENODE*head,*tailvoidenqueuel(charx){NODE*pp=(NODE*)malloc(sizeof(NODE))p>data=xp>link=if(head==)head=pelsetail>link=ptail=p}intdequeuel(char*py){NODE*pif(head==)return()*py=head>datap=headhead=head>linkfree(p)return()}voidmain(){NODE*pcharchx,chyprintf("inputthecharyouwanttoenqueuen")scanf("c",chx)while(chx!=''){enqueuel(chx)getchar()scanf("c",chx)}p=(NODE*)malloc(sizeof(NODE))p=headwhile(p!=){printf("c",p>data)p=p>link}printf("n")if(dequeuel(chy)==)printf("failure!n")else{printf("success!n")printf("Thedequeuechariscn",chy)}p=(NODE*)malloc(sizeof(NODE))p=headwhile(p!=){printf("c",p>data)p=p>link}printf("n")}程序:循环队列的实现和运算#include<stdioh>#include<stringh>#defineMAXNcharqMAXNinthead=,tail=intencq(charx){tail=(tail)MAXNif(tail==head){if(tail==)tail=MAXNelsetailreturn()}qtail=xreturn()}intdecq(char*py){if(head==tail)return()head=(head)MAXN*py=qheadreturn()}voidmain(){inticharchx,chyprintf("inputthecharyouwanttoenqueuen")scanf("c",chx)while(chx!='')if(encq(chx)==)printf("failure!n")else{printf("success!n")printf("inputacharforchxtoenqueuenchx=")getchar()scanf("c",chx)}i=while(qi!=''){printf("c",qi)i}if(decq(chy)==)printf("failure!n")else{printf("success!n")printf("Thedequeuechariscn",chy)}for(i=headi<=taili)printf("c",qi)}五、写出输入数据及运行结果

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/7

实验二、栈和队列的应用

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利