• 当前位置:首页>>C语言>>C语言编程实例>>停车场管理
  • 停车场管理
  • 各位大虾,小弟编了一个小程序,是用TC编的。主要的要求是:设有一个车站,用栈的结构表示;车站的外面有边道,用队列的结构表示。当车辆进栈的时候,如果栈中有空位,则进栈;如果没有空位,则在边道上等候,直到有栈中的车辆出栈才可以进栈。且出栈的车辆要按在栈中停留的时间交纳费用。
    我在其中设了一个辅助栈,用来临时容纳为要给离去的车辆让路而退出来的车辆。输入的数据有三个数据项:车辆的进栈或出栈,车牌号,车子"进出栈"的时刻;栈中则为车牌号,"进栈"的时刻;队列中则为车牌号,因为车辆在边道上的等待时间并不计入费用中。
    我的结果可以出来,但是我不明白的是:我每输入一条命令后,无论结果如何都会出现  The order is wrong!和Input the order!:     这是我无法理解的!
    以下便是我的源程序:
     #include<stdio.h>
     #include<stdlib.h>
     struct {
     char status;
     int num;
     int time;
     }a;                                                  /*命令的结构*/
     typedef struct{
     int num;
     int time;
     }Element;                                     
     struct {
     Element *base;
     Element *top;
     int stacksize;
     }S,VS;                                          /*S为栈,VS为辅助栈*/
     void main(){
     typedef struct{
      int num;
      struct QNode *next;
      }QNode,*QueuePtr;
      QueuePtr l;
     struct {
     QueuePtr front;
     QueuePtr rear;
     }Q;                                                 /*队列*/
        int n,x,m=0,order,money,b=0;
        printf("\nInput the size of the garage and the cost per hour:");
        scanf("%d%d",&n,&x);
        S.base=(Element*)malloc(n*sizeof(Element));
        S.top=S.base;
        S.stacksize=n;
        VS.base=(Element *)malloc((n-1)*sizeof(Element));
        VS.top=VS.base;
        VS.stacksize=n-1;
        Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
        Q.front->next=NULL;                                                       /*各结构的初始化*/
        while (b!=1){
      printf("\nInput the order!:");
      scanf("%c,%d,%d",&(a.status),&(a.num),&(a.time));
      switch(a.status)
            {
      case 'E':b=1;break;
      case 'A':
        if (S.top-S.base<S.stacksize){
            (*(S.top)).num=a.num;
            (*(S.top)).time=a.time;
            S.top++;
            order=S.top-S.base;
            printf("The %d car is in the %d of garage!\n",a.num,order);
        }
        else {
             Q.rear=(QueuePtr)malloc(sizeof(QNode));
                                                               Q.rear->next=NULL

    [1] [2] 下一页