ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:17.74KB ,
资源ID:8026261      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8026261.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据结构栈.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据结构栈.docx

1、数据结构栈栈:#includetypedef int Elem; #define N 100/*N是栈的足够的空间*/ Elem stackN; int top;/*栈顶指针,当栈为空时top=1,即top指向栈顶元素的上一个元素*/ /*定义栈的一般方法*/ void Init_Stack()/*栈的初始化*/ top=1;/*清空栈*/ int IsEmpty()/*判断栈是否为空*/ if (top=N)return 1; else return 0; void Push_Stack(Elem x)/*入栈函数*/ if (IsFull()printf(Stack is full,can

2、not push element!);exit(0); stacktop=x; top+; Elem Pop_Stack()/*出栈函数*/ Elem ret; if(IsEmpty()printf(Stack is empty,cannot pop element!n);exit(0); top-; ret=stacktop; return ret; main()/*用作测试*/ int i=0; Init_Stack(); for (i=0;i10;i+) Push_Stack(i); for (i=0;i10;i+) printf(%4d,Pop_Stack(); 栈的逆转程序:(正确的

3、)( #include #define MAXN 26int stackMAXN;int top=0;int sMAXN; main()int j,k,i;printf(nInput the number:n);for (k=0;k10;k+)scanf(%d,&sk);printf(nThe number is the group are:n);for (k=0;k10;k+)printf(%d ,sk);for (k=0;k=0;j-)printf(%d ,stackj);int push(x)int x;if (top=MAXN)return (1);stacktop+=x;return

4、 (0);运行结果:Input the number:0 1 2 3 4 5 6 7 8 9The number is the group are:0 1 2 3 4 5 6 7 8 9The order poped from the stack is:9 8 7 6 5 4 3 2 1 0/*迷宫游戏*/ /*进入tc运行游戏,按上下左右键控制,任何时候按ESC键退出*/ #include #include #include #include #defineLEFT120 #defineTOP40 #defineRIGHT520 #defineBOTTOM440 #defineSMALL20

5、 intb2020;/*用来保存地图信息*/ b2020=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,1,1,1, 1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1, 1,0,1,0,1,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1, 1,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,1, 1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,0,0,1,0,1, 1,1,0,0,1,1,0,0,1,0,0,1,0

6、,1,1,0,1,0,0,1, 1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1, 1,0,1,1,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, 1,0,1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,0,1,1, 1,0,0,0,1,1,0,1,0,0,0,1,1,0,1,0,1,0,0,1, 1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1,1,0,1, 1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1, 1,1,0,1,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1,

7、1, 1,0,0,0,1,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1, 1,0,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,1,0,1, 1,0,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1, 1,0,1,1,0,0,0,0,1,0,1,1,0,0,1,0,0,0,1,1, 1,0,0,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1; voiddrawcake(intx,inty)/*划方块*/ setfillstyle(SOLID_F

8、ILL,BLUE); bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL); voiddraw(intx,inty)/*划小方块*/ setfillstyle(SOLID_FILL,RED); bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL); voidundraw(intx,inty)/*擦去小方块*/ setfillstyle(SOLID_FILL,BLAC

9、K); bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL); main() intgr=DETECT,gm,k=0,i,j,x=1,y=1,ch; floatf; initgraph(&gr,&gm,); cleardevice(); setbkcolor(0); for(i=0;i20;i+) for(j=0;j20;j+) if(bij=1)drawcake(j,i); draw(x,y); do ch=bioskey(0); switch(ch) case19200:/*

10、按向左键*/ if(byx-1=0) undraw(x,y); byx=0; x-; draw(x,y); byx=2; break; case19712:/*按向右键*/ if(byx+1=0) undraw(x,y); byx=0; x+; draw(x,y); byx=2; break; case18432:/*按向上键*/ if(by-1x=0) undraw(x,y); byx=0; y-; draw(x,y); byx=2; break; case20480:/*按向下键*/ if(by+1x=0) undraw(x,y); byx=0; y+; draw(x,y); byx=2;

11、 break; if(b1818=2)ch=283; while(ch!=283); if(b1818=2)printf(恭贺你成功地走出了迷宫!); getch(); 用栈实现的迷宫寻径演示:#include #include #include #include #include #defineCOL20 #defineROW20 #defineLEFT120 #defineTOP40 #defineRIGHT520 #defineBOTTOM440 #defineSMALL20 intMazeCOLROW= 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

12、1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,1,1,1, 1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1, 1,0,1,0,1,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1, 1,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,1, 1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,0,0,1,0,1, 1,1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,1,0,0,1, 1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1, 1,0,1,1,0,0,1

13、,1,0,1,1,0,1,1,0,1,1,0,1,1, 1,0,1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,0,1,1, 1,0,0,0,1,1,0,1,0,0,0,1,1,0,1,0,1,0,0,1, 1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1,1,0,1, 1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1, 1,1,0,1,1,0,1,0,0,1,0,1,1,1,0,1,1,0,1,1, 1,0,0,0,1,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1, 1,0,1,0,1,0,0,0,0,1,0,0,0,

14、1,1,0,0,1,0,1, 1,0,1,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1, 1,0,1,1,0,0,0,0,1,0,1,1,0,0,1,0,0,0,1,1, 1,0,0,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1; intflag=1; typedefstructSeat intx,y; intdir; Seat; typedefstructLSNode Seatdata; structLSNode*next; LSNode,*SNode; typede

15、fstructLSk SNodetop; LSk,*LStack; voidInitLStack(LStackLS) if(LS=NULL) LS=(LStack)malloc(sizeof(LSk); LS-top=NULL; Seat*Peek(LStackLS) Seat*p; Seattemp; temp=LS-top-data; p=(Seat*)malloc(sizeof(Seat); p-dir=temp.x; p-x=temp.x; p-y=temp.y; returnp; voidPush(LStackLS,Seatvalue) SNodep; p=(SNode)malloc

16、(sizeof(LSNode); p-data.x=value.x; p-data.y=value.y; p-data.dir=value.dir; p-next=LS-top; LS-top=p; Seat*Pop(LStackLS) SNodep; Seat*res; Seattemp; res=(Seat*)malloc(sizeof(Seat); res-x=-1; res-y=-1; res-dir=0; p=LS-top; if(p=NULL) flag=0; returnres; temp=p-data; res-x=temp.x; res-y=temp.y; res-dir=t

17、emp.dir; LS-top=p-next; returnres; intIsEmpty(LStackLS) if(LS-top=NULL) return1; else return0; voidPrint(LStackLS) SNodep; if(LS-top=NULL) printf(Nopathn); return; p=LS-top; printf(Pathisasfollow:n); while(p!=NULL) printf(%d,%dt,p-data.x,p-data.y); p=p-next; printf(n); voiddrawcake(intx,inty) setfil

18、lstyle(SOLID_FILL,BLUE); bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL); voiddraw(intx,inty) setfillstyle(SOLID_FILL,RED); bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL); voidundraw(intx,inty) setfillstyle(SOLID_FILL,BLACK);

19、 bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL); voidfootprint(intx,inty) setfillstyle(SOLID_FILL,GREEN); bar(LEFT+5+x*SMALL,TOP+5+y*SMALL,RIGHT-5-19*SMALL+x*SMALL,BOTTOM-5-19*SMALL+y*SMALL); voidTranverse(Seatstart,Seatend,LStackLS) Seatcur; Seat*top; start.dir

20、=1; Push(LS,start); top=Peek(LS); while(!IsEmpty(LS)&(top-x!=end.x|top-y!=end.y) top=Pop(LS); cur.x=top-x; cur.y=top-y; cur.dir=top-dir; /*printf(%d,%d,%dt,cur.x,cur.y,cur.dir);*/ if(cur.dir=5) Mazecur.xcur.y=0; footprint(cur.y,cur.x); continue; else switch(cur.dir) case1: if(cur.y+1COL) if(Mazecur.xcur.y+1=0) Mazecur.xcur.y+1=2; cur.dir=2; Push(LS,cur); cur.dir=1; cur.y+=1; Push(LS,cur); draw(cur.y,cur.x); break; cur.dir=2; Push(LS,cur); break; case2: if(cur.x+1=0) if(Mazecur.xcur.y-1=0) Mazecur.xcur.y-1=2; cur.dir=4; Push(LS,cur); cur.dir=1; cur.y-=1; Push(LS,cur);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1