| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 909 人关注过本帖, 1 人收藏
标题:停车场的代码
只看楼主 加入收藏
fydgo
Rank: 2
等 级:论坛游民
帖 子:57
专家分:10
注 册:2009-4-10
结帖率:73.33%
收藏(1)
已结贴  问题点数:15 回复次数:2 
停车场的代码
我们做课程设计,题目是停车场,我写了代码,但总是出错,代码写的也不完整,就是进入的时候有时间,出来的时候没写时间,但这现在无所谓,问题是编译没问题,但运行的时候进入车站函数后总是死循环,求高手帮我一下,代码错的也帮我改一下,感激不尽
#include <stdio.h>

typedef struct car
{
   int hour;
   int number;
   int minite;
}Car;

typedef struct stack
{
   int base;
   int top;
   Car *s[3];
}STack;

typedef struct QNode
{
   Car *data;
   struct QNode *next;
}QNode,*Queueptr;

typedef struct
{
   Queueptr front;
   Queueptr rear;
}LinkQueue;

initstack(STack *ET)                                                                                   /*初始化栈,包括临时栈*/
{
  ET->base=ET->top=-1;
}

initQueue(LinkQueue  *D)                                                                           /*初始化队列*/
{
  D->front=D->rear=(Queueptr)malloc(sizeof(QNode));
  if(!D->front) exit (1);
  D->front->next=NULL;
 }
menu()
{
   printf("Now please choice.1......................enter\n");
   printf("                  2.......................leave\n");
   printf("                  3.......................information\n");
}

 push(STack *enter,LinkQueue  *d)                                                            /*进入车站*/
 {
      Car *p;
      LinkQueue *w;
      printf("please enter the car information:number,time(xx,xx):");                 /*按,逗号输出如111,11,11 车牌号是111,时间是11点11分*/
      scanf("%d,%d,%d",&p->number,&p->hour,&p->minite);
      if(enter->top>=2)                                                                             /*为了简单,只能进入2辆车,当等于大于2时车站满,进入等候区,也就是进入队列*/
      {
        printf("the car park is full,you must wai:");
        w=(Queueptr)malloc(sizeof(QNode));                                                /*分配空间*/
        w->data=p;w->next=NULL;
        d->rear->next=w;
        d->rear=w;
        return 1;
      }
      else
      {
        printf("you can enter the park:");                                                         /*进入栈,也就是进入停车场*/
        enter->top++;                                                                                  /*进入栈的,这么写可以吗,书上是把两句换了,我觉得这样也可以,所以这么写的*/
        enter->s[enter->top]=p;
      }
  }

gettop(STack *enter,STack *temp,LinkQueue  *d)                                       /*出战,也是从停车场出来*/
 {
     int i,j;
     Car *t;
     if(enter->top==-1)
     {
        printf("there is no car in the park:");
     return 1;
     }
     else
     {
        printf("please enter the leave location:");                                              /*选择出栈的位置*/
        scanf("%d",&i);
        while(enter->top!=i-1)                                                                       
        {
              temp->top++;                                                                            /*进入临时栈*/
              temp->s[temp->top]=enter->s[enter->top];
              enter->top--;                                             
        }
        while(temp->top!=-1)                                                                       /*进入临时栈的要进入主栈*/
        {
            enter->top++;
            enter->s[enter->top]=temp->s[temp->top];
            temp->top--;
        }
       if(d->front!=d->rear)                                                                       /*等候区有车的话进入停车场*/
       {
         t=d->front->next;
         d->front->next=t->next;
         enter->top++;
         enter->s[enter->top]=t->data;
     if(d->rear==t) d->front=d->rear;
     free(t);
        }
  }
}

 park(STack *enter)                                                                                                          /*停车场信息*/
 {
    int i;
    Car *p;
    printf("there is %d car in the park",enter->top+1);
    for(i=0;i<=enter->top;i++)
    printf("arrive number:%d,arrive time is %d:%d",p->number,p->hour,p->minite);
 }
 wait( LinkQueue  *d)                                                                                                        /*等车信息*/
  {
     if(d->front==d->rear)
     printf("there is no car waiting");
     else
     printf("there is car in the waiting");
  }
 information(STack *enter,LinkQueue  *d)                                                                            /*车辆信息函数*/
 {
    int op;
    printf("please choice:\n");
    printf("1,car park information:\n");
    printf("wait information:\n");
    scanf("%d",&op);
    switch(op)
    {
        case 1:park(enter);     break;
        case 2:wait(d);           break;
    }
 }
 main()

 {
    int i,j,op;
    STack *enter,*temp;
    LinkQueue  *d;
    initstack(enter);
    initstack(temp);
    initQueue(d);
    menu();
    printf("please choic:");
    scanf("%d",&op);
    do
    {
        switch(op)
        {
             case 1:push(enter,d);    break;                                                              /*输入后总是死循环*/
             case 2:gettop(enter,temp,d); break;
            case 3:information(enter,d);   break;

        }
       printf("please choice again:");
       scanf("%d",&op);
   }while(op);
 }
搜索更多相关主题的帖子: 代码 停车场 
2009-11-15 00:18
平凡不在
Rank: 2
等 级:论坛游民
帖 子:39
专家分:69
注 册:2009-8-7
收藏
得分:15 
把题目要求说清楚!
2009-11-16 14:10
迷失の夏天
Rank: 1
来 自:江苏南京
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-5-20
收藏
得分:0 
就是啊,把题目写出来
2011-06-14 09:34
快速回复:停车场的代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027123 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved