停车场管理系统

上传人:第*** 文档编号:33988937 上传时间:2018-02-19 格式:DOC 页数:8 大小:54KB
返回 下载 相关 举报
停车场管理系统_第1页
第1页 / 共8页
停车场管理系统_第2页
第2页 / 共8页
停车场管理系统_第3页
第3页 / 共8页
停车场管理系统_第4页
第4页 / 共8页
停车场管理系统_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《停车场管理系统》由会员分享,可在线阅读,更多相关《停车场管理系统(8页珍藏版)》请在金锄头文库上搜索。

1、/顺序栈类定义template class SqStackpublic:T *base;/栈底指针int top;/栈顶int stacksize;/栈容量public:SqStack(int m);/构建函数SqStack()delete base;top=-1;stacksize=0;/析构函数void Push(T x);/入栈T Pop();/出栈T GetTop();/获取栈顶元素bool StackEmpty();/测栈空bool StackFull();/栈满void ClearStack();/清空栈void StackTop();/返回栈顶指针void StackTranve

2、rse();/显示栈中元素;/顺序栈类实现template SqStack:SqStack(int m)base=new Tm;if(base=NULL) coutvoid SqStack:Push(T x)if(top=stacksize-1) throw 栈满,无法入栈;top+;basetop=x;/coutT SqStack:Pop()T x;if(top=-1) throw 栈空,不能出栈 ;x=basetop-;return x;template T SqStack:GetTop()if(top=-1)throw 栈空,栈顶无元素 ;return basetop;template

3、bool SqStack:StackEmpty()if(top=-1) return true;elsereturn false;template void SqStack:ClearStack()top=-1;template void SqStack:StackTop()/返回栈顶指针coutvoid SqStack:StackTranverse()int i=top;while(i=0) coutbool SqStack:StackFull()returntop=stacksize-1;/链队类的定义templatestruct NodeT data;Node *next;/此处 T 可

4、以省略;templateclass LinkQueueprivate:Node *front;/队头指针,链表头为队头Node *rear;/队尾指针,链表尾为了队尾public:LinkQueue();/构造空队列LinkQueue();/ 析构函数,释放链队各结点的存储空间void EnQueue(T x);/ 元素 x 入队T DeQueue();/ 队顶元素出队T GetHead();/ 取队头元素T GetLast();/取队尾元素int QueueEmpty(); / 判断队是否为空void ClearQueue();/void QueueTranverse();/;/链队类的实现

5、templateLinkQueue:LinkQueue()/构建函数,创建一空队front=new Node;/创建队头结点front-next=NULL;rear=front;/空队templateLinkQueue:LinkQueue()/析构函数,销毁队Node *p;while(front!=NULL)/从队头开始逐个删除队列中的结点p=front;/暂存被释放结点front=front-next;/头指针后移指向下一个被释放结点delete p;templatevoid LinkQueue:EnQueue(T x)/入队Node *s;s=new Node; s-data=x; /申

6、请一数据域为 x 的结点 ss-next=rear-next;rear-next=s; /新结点插在链队尾rear=s; /修改尾指针if(front-next=NULL)/如果创建的是首元结点, front-next 指向它front-next=s;templateT LinkQueue:DeQueue()/出队T x;Node *p;if(rear=front) throw下溢;/ 队空,则下溢p=front-next;x=p-data;/暂存队头元素front-next=p-next;/将队头结点从链表中摘除if(p-next=NULL) rear=front;/如果出队后为空队,修改队

7、尾指针delete p;return x;template T LinkQueue:GetHead()/获取队头元素Node *p;if(front=rear) throw 队空,无队头元素;/p=front-next;return p-data;template T LinkQueue:GetLast()/获取队尾元素if(front=rear) throw 队空,无队尾元素;return rear-data;template void LinkQueue:ClearQueue()/清空队Node *p;p=front-next;while(p)/从队头开始逐个删除队列中的结点front-n

8、ext=p-next;/暂存被释放结点delete p;p=front-next;rear=front;template int LinkQueue:QueueEmpty()/测队空if(front=rear) return 1;elsereturn 0;/*template void LinkQueue:QueueTranverse()/从队首到队尾,遍历输出队中元素Node *p;p=front-next; while(p)coutdatanext;cout/cout,cin#includeSqStack.h#includeLinkQueue.h/char pause;using name

9、space std;struct carint license;double h;double m;/主函数int main() int license;int size=0;double hour,minute; /int size=0;SqStack pCar(5);SqStack tempCar(5);LinkQueue noCar;car newCar,newCar1;/SqStack s(5);/建立容量为 5、元素类型为整型的空栈system(cls);/执行系统命令 cls,清屏int choice;do/显示主菜单coutchoice;switch(choice)case 1:

10、/入栈coutlicense;/couthour;cinminute;newCar.license=license;newCar.h=hour;newCar.m=minute;if(!pCar.StackFull()pCar.Push(newCar); /size+;coutlicense;while(!pCar.StackEmpty()&pCar.GetTop().license!=license) tempCar.Push(pCar.GetTop();pCar.Pop(); if(pCar.GetTop().license=license)double time; couthour;cin

11、minute;time=hour+minute/60-(pCar.GetTop().h+pCar.GetTop().m/60);couthour;cinminute;couthour;cinminute;noCar.GetHead().h=hour;noCar.GetHead().m=minute; pCar.Push(noCar.GetHead();size-;noCar.DeQueue();break;case 3:/cout程序结束,Bye-Bye!endl;break;default:coutInvalid choicen;break;coutendl;while(choice!=3);return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号