退栈C语言,C语言编程:顺序栈的入栈与退栈及读顶元素

2008-11-09 回答

举一个例子说明 《停车场管理》 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #include "stdio.h" #include "malloc.h" #define max_stop 5 // 停车场容量// #define price 8 //停车单价 // typedef struct//汽车// { char *license[20]; //汽车// }car; typedef struct //停车场// { car stop[max_stop]; //停车场// int top; }parking; void come(car p,parking *tcc) { if(tcc->top>=max_stop-1){printf("已满!!");} else { printf(" 输入到来汽车的车牌号码 : "); scanf("%s",p.license); printf("\n"); tcc->top++; tcc->stop[tcc->top]=p;//如果停车场没有满就入场// } } void display(car p,parking *tcc) { int n=0; if(tcc->top==-1)printf(" 停车场内无汽车!\n"); //指针在-1处 停车场内无车// else{ // 有车 // printf("●停车场内的车为:\n"); while(n<=tcc->top) { printf("第 %d 辆 %s\n",n+1,tcc->stop[n].license); n++; } } } void leave(car p,parking *tcc) { car leavecar; int num,money,time; printf(" 输入将要离开的汽车车位号码:"); scanf("%d",&num); num--; if(num>tcc->top||num<0)printf(" 你的输入有误 请检查预备出停车场的车辆号码\n"); else { printf(" 输入此车停留的时间 : "); scanf("%d",&time); if(time<=0)printf(" 你的输入有误 请检查停车时间\n"); else { leavecar=tcc->stop[num]; while(numtop) { tcc->stop[num]=tcc->stop[num+1]; num++; } tcc->top--; } } if((num<=tcc->top) && (num>=0)) { money=time*price; printf("● %s 已经离开停车场 停留%d小时 收费%d元",leavecar.license,time,money); } } void welcome() //欢迎界面// { printf(" ●欢迎适用本程序●\n"); printf(" 本程序为停车场的模拟管理程序,有车到来时请按 c 键\n"); printf(" 然后根据屏幕提示进行相关操作,有车要走时请按 l 键\n"); printf(" 然后根据屏幕提示进行相关操作,若需要帮助请按 h 键\n"); printf(" 然后根据屏幕提示进行相关操作,要退出程序请按 q 键\n"); } void main() { char key; car p; parking *tcc; tcc=(parking *)malloc(sizeof(parking)); tcc->top=-1; while(1) { flushall(); printf(" 请输入您的操作 : "); scan

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值