欢迎来到天天文库
浏览记录
ID:44345794
大小:104.66 KB
页数:6页
时间:2019-10-21
《商品货架管理——C实现》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、//head.h(头文件)〃定义一个队列structQueue{int*Qlist;intmaxsize;intrear,front;};〃初始化〃清空队列〃判队空〃判队满〃插入新元素进队〃按大小顺序排队〃岀队列〃定义一个栈voidInitQueue(Queue&QL,constintms);voidClearQueue(Queue&QL);intQueueEmpty(Queue&QL);intQueueFullfQueue&QL);boollnsertQueue(Queue&QL,constint&item);voidOrderQueue(Queue&QL);intDeQueue(Queu
2、e&QL);structstack{int*Slist;inttop;intMaxsize;};〃栈初始化〃判栈空〃栈满〃清空栈〃新元素推进栈〃出栈〃输出栈屮元素voidlnitstack(stack&SL,constintMS);boolStackempty(stack&SL);boolStackfull(stack&SL);voidClearstack(stack&SL);intPushfstack&SL,int&item);intPop(stack&SL);voidTraverstack(stack&SL);//achieve,h(实现文件)#include#in
3、clude#include"head.h"〃初始化队列voidInitQueue(Queue&QL,constintms){QL.QIist=newint[ms];if(IQLQIist){cerr«”给队列分配内存失败vvendl;exit(l);}〃各项值,初始化〃清空队列〃判空QL.rear=0;QL.front=0;QL.maxsize=ms;}voidClearQueue(Queue&QL){QL.front=QL.rear=0;}intQueueEmpty(Queue&QL){returnQL.rear==QL.front;}intQueueFull(Queu
4、e&QL){return(QL.rear+1)%QL.maxsizebooIInsertQueue(Queue&QL,constint&item){if(QueueFull(QL)){cerr«"Queueisfull"«endl;=QL.front;}//判满〃插入元素进队exit(l);}讦(QL.rearvQL.maxsize){QL.QIist[QL.rear]=item;QL.rear=(QL.rear+1)%QL.maxsize;}〃尾指针不能超过maxsizereturntrue;}voidOrderQueue(Queue&QL){讦(QueueEmpty(QL)){cout«
5、"Queueisemptynow”«endl;exit(l);}inti,j,item;for(i=0;i6、化〃判空〃判满〃清空栈〃元素进栈〃元素出栈〃输出栈QL.front=(QL.front+1)%QL.maxsize;returntemp;}voidlnitstack(stack&SL,constintMS){SL.Slist=newint[MS];if(!SL.SIist){cout«"给栈分配内存失败。"«endl;exit(l);}SL.Maxsize=MS;SL.top=-1;}boolStackempty(stack&SL){returnSL.top==-1;}boolStackfull(stack&SL){returnSL.top==SL.Maxsize;}voidClearst7、ack(stack&SL){SL.top=-1;}intPush(stack&SL,int&item){if(Stackfull(SL))returnfalse;SL.top++;SL.SIist[SL.top]=item;returnSL.SIist[SL.top);}intPop(stack&SL){if(Stackempty(SL))returnfalse;returnSL.SIist[SL.top-]
6、化〃判空〃判满〃清空栈〃元素进栈〃元素出栈〃输出栈QL.front=(QL.front+1)%QL.maxsize;returntemp;}voidlnitstack(stack&SL,constintMS){SL.Slist=newint[MS];if(!SL.SIist){cout«"给栈分配内存失败。"«endl;exit(l);}SL.Maxsize=MS;SL.top=-1;}boolStackempty(stack&SL){returnSL.top==-1;}boolStackfull(stack&SL){returnSL.top==SL.Maxsize;}voidClearst
7、ack(stack&SL){SL.top=-1;}intPush(stack&SL,int&item){if(Stackfull(SL))returnfalse;SL.top++;SL.SIist[SL.top]=item;returnSL.SIist[SL.top);}intPop(stack&SL){if(Stackempty(SL))returnfalse;returnSL.SIist[SL.top-]
此文档下载收益归作者所有