一个菜鸟级别的问题,关于数据结构的停车场代码的,求救!!!!!!!!!

tanzhiliang200 2010-10-26 09:17:17
题目是这样的:
设计要求:
1.模拟上述管理过程。要求以顺序栈模拟停车场,以链队列模拟便道。
2.从终端读入汽车到达或离去的数据,每组数据包括三项:
(1)是“到达”还是“离去”;
(2)汽车牌照号码;
(3)“到达”或“离去”的时刻。
3.与每组输入信息相应的输出信息为:如果是到达的车辆,则输出其在停车场中或便道上的位置;如果是离去的车辆,则输出其在停车场中停留的时间和应交的费用。
提示:需要另设一个栈,临时停放为让路而从停车场退出的车。


而我的代码是这样的:
#include<stdio.h>
#define NULL 0
#define true 1
#define false 0
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define StackSize 3 //停车场容量
typedef struct time{
int hour;
int min;
}Time; /*时间结点*/

typedef struct
{ //车辆信息
char license[30];//车牌号码
Time reach;//车辆到达时间
Time leave;//车辆离开时间
int stop;//车辆所在的车位
}carinfo;

typedef carinfo datatype;

typedef struct//停车场信息
{
datatype items[StackSize];//车辆数目
int top;//用来存放栈顶元素的下标,同样表示为车位数目
}Sqstack;

typedef struct QNode//便道基本信息
{
datatype data;
struct QNode *next;
}LinkQueueNode,*Node;

typedef struct//定义便道的头指针和尾指针
{
LinkQueueNode *front;
LinkQueueNode *rear;
}LinkQueue;







/*以顺序栈模拟停车场,下面是停车场的相关操作*/
void InitStack(Sqstack *S)//构造一个空栈
{
S->top=-1;
}

int IsEmpty(Sqstack *S)//判断S为空栈时返回值为真,反之为假
{
return(S->top==-1?true:false);
}

int IsFull(Sqstack *S)//判断S为满栈时返回为真,反之为假
{
return(S->top==StackSize-1?true:false);
}

int Push(Sqstack *S,datatype *car)
{
if(S->top==StackSize-1)
return false;
else
S->top++;
S->items[S->top]=*car;
return true;
}

int Pop(Sqstack *S,datatype *car)
{
if(S->top==-1)//栈为空
return false;
else
{
*car=S->items [S->top];
S->top--;
return true;
}
}





/*以队列创建便道*/
int InitQueue(LinkQueue *pave)//将Q初始化为一个空的链表队
{
pave->front=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
if(pave->front!=NULL)
{
pave->rear=pave->front;//头指针和尾指针指向同一结点
pave->front->next=NULL;
return true;
}
else
return false;//溢出
}

int EnterQueue(LinkQueue *pave,datatype x) //入队
{
LinkQueueNode *NewNode;
NewNode=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
if(NewNode!=NULL)
{
NewNode->data=x;
NewNode->next=NULL;
pave->rear->next=NewNode;
pave->rear=NewNode;
return 1;
}
else
return 0;//溢出
}

int DeleteQueue(LinkQueue *pave,datatype *x)//将队列Q的队头元素出队,并存放到x所指的存储空间中
{
LinkQueueNode *p;
if(pave->front==pave->rear)
return 0;
p=pave->front->next;
pave->front->next=p->next;//队头元素p出列
if(pave->rear==p)//如果队中只有一个元素p,则p出队后成为空队
pave->rear=pave->front;
*x=p->data;
free(p);//释放存储空间
return 1;
}

int EmptyQueue(LinkQueue *pave)
{
if(pave->front->next==NULL)
return 1;
else
return 0;
}









int Reach(Sqstack *park,LinkQueue *pave) /*车辆到达停车场*/
{
datatype *car;
car=(datatype *)malloc(sizeof(datatype));//申请空间
if(!car)
{
printf("Car out wrong\n.");//车辆出入出错
return false;
}
printf("\nWelcome to enter! Please input within:");//欢迎进入!请输入车牌号
scanf("%s",car->license);
if(park->top>=StackSize-1) //停车场已满,请进入便道等待
{
printf("Parking is already full, please enter shortcuts to wait......\n");//停车场已满,请进入便道等待
EnterQueue(pave,*car);//进入便道
printf("%s\n",pave->rear->data.license);
printf("%s\n",pave->front->next->data.license);
}
else
{
printf("\nplease input the reach time:/**:**/:");
scanf("%d%d",&(car->reach.hour),&(car->reach.min));//获取开始时间
car->stop=park->top+1;//停车场的车辆数加1
Push(park,car);//进入停车场
printf("\nPlease enter No.%d parking space vehicles.\n",car->stop+1);//请车辆进入第%d号停车位
}
return true;
}


void Leave(Sqstack *park,Sqstack *way,LinkQueue *pave) //车辆离开
{
int locate;
float price=1;
datatype *p,*t;
if(!IsEmpty(park))//判断停车场是否为空
{
printf("\nPlease input from the parking space vehicles(1~%d):",park->top+1);//不为空,请输入离开车辆的停车位号
scanf("%d",&locate);
while(park->top!=locate-1)//排在离开车辆之前的车辆进入临时栈
{
Pop(park,p);//弹出车辆
Push(way,p);//把已弹出的车辆压入临时栈
}
Pop(park,p);//弹出车辆
printf("please input the depart time /**:**/:");
scanf("%d%d",&(p->leave.hour),&(p->leave.min));//输入离开时间
printf("\n------------------------Leave vehicle information-------------------------\n");//离开车辆信息
printf("\n");
printf("parking-space:%d\n",p->stop+1);//停车位
printf("within:%s\n",p->license);//车牌号
printf("cost:%10.2f yuan\n",(((p->leave.hour)-(p->reach.hour))*60+((p->leave.min)-(p->reach.min)))*price);//应缴费用
printf("Arrival-time:%d:%d\n",(p->reach.hour),(p->reach.min));//到达时间
printf("Leave-time:%d:%d\n",(p->leave.hour),(p->leave.min));//离开时间
while(way->top!=(-1))//排在离开车辆之前的所有车辆从临时栈回到停车场
{
Pop(way,p);//从临时栈弹出来
Push(park,p);//回到停车场
}
if((!EmptyQueue(pave))&&(park->top<(StackSize-1)))//如果便道上不空,而停车场不满,则便道上的车辆进入停车辆
{
DeleteQueue(pave,t);
printf("\nThe pavement, the %s car get into the %d parking space..\n",t->license,park->top+2);//便道上的%s号车进入第%d个停车位
printf("please input the start time:\n");
scanf("%d%d",&(p->reach.hour),&(p->reach.min));//停车开始计时
t->stop=park->top+1;//停车场车辆数加1
Push(park,t);//临时栈的车进入停车场
}
else
printf("The pavement no car.\n");//便道上没有车
}
else
printf("\nNo car parking lot");//停车场内没有车
}

void DispPark(Sqstack *park)//显示停车场信息
{
int i;
if(IsEmpty(park))//停车场内没有车辆
printf("No parking cars!");//停车场没有车辆
else
{
printf("\nparking-space within Arrival-time\n");//停车位 车牌号 到达时间
printf("-------------------------------------------------\n");
for(i=0;i<=park->top;i++)
{
printf(" \t%d \t ",i+1);
printf(" %s ",park->items[i].license);
printf(" %d:%d\n",(park->items[i].reach.hour),(park->items[i].reach.min));
}
}
}

void DispPave(LinkQueue *pave)//显示便道的车辆信息
{
LinkQueueNode *p;
p=pave->front->next;
if(pave->front==pave->rear)//判断便道上是否为空
printf("No waiting vehicles\n");//没有等待的车辆
else//不为空
{
printf("Following vehicles in wait state:\n");//以下车辆处于等待状态
printf("within:");//车牌号
while(p!=NULL)
{
printf("%s\n",p->data.license);
p=p->next;
}
}
}

void main()
{
Sqstack *park,*way;//停车场
LinkQueue *pave;//便道
int choice;
InitStack(park);//初始化停车场
InitStack(way);//初始化让路的临时栈
InitQueue(pave);//初始化便道
do
{
printf("\n--------------------The main menu--------------------\n");//主菜单
printf("(1)Get......\n");//车辆到达
printf("(2)Leave......\n");//车辆离开
printf("(3)Display parking information......\n");//显示停车场信息
printf("(4)Waiting vehicles that information......\n");//显示等待车辆信息
printf("(5)Exit system......\n");//退出系统
printf("\nPlease choose(1,2,3,4,5):");//请选择
scanf("%d",&choice);
if(choice<1&&choice>5)
printf("Your choice is not within the scope of system:\n");//你的选择不在系统范围之内
else
switch(choice)
{
case 1:Reach(park,pave);break;//车辆到达停车场
case 2:Leave(park,way,pave);break;//车辆离开
case 3:DispPark(park);break;//显示停车场信息
case 4:DispPave(pave);break;//显示便道上等待车辆的信息
case 5:exit(0);
default:break;
}
}while(1);
}



我是在用turboC++3.0运行的
输出便道那里出现乱码,还有很多问题我不懂的说,大家帮我测试一下,最好用turboC++3.0,因为我用VC是运行不了的,其他编译器好像也不行,大家帮帮忙
...全文
372 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
y2906006011 2010-10-26
  • 打赏
  • 举报
回复
是有点长啊!自己再认真看看吧。。。。。会很有收获的
ForestDB 2010-10-26
  • 打赏
  • 举报
回复
LZ只能靠自己了。
luciferisnotsatan 2010-10-26
  • 打赏
  • 举报
回复
好长啊,lz自己调试下看看

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧