数据结构 停车场程序
这个程序编写后有一下报错信息
E:/Panda/改1.c 0 -1 In function 'QueueEmpty':
E:/Panda/改1.c 101 6 [警告] 'main' is normally a non-static function [-Wmain]
E:/Panda/改1.c 214 1 [错误] expected declaration or statement at end of input
也就是一下代码的 int main() 和最后一行的 } 符号
问一下这是为什么,排查了两个钟头了真的看不出来了
#include<stdio.h>
#include<malloc.h>
#define N 10 //停车场内最多可以停放的车辆数
#define M 10 //候车场内最多可以停放的车辆数
#define Price 3 //每单位时间停车费用
typedef struct
{
int CarNo[N]; //车牌号
int CarTime[N]; //进场时间,整点记录
int top; //栈指针
} SqStack; //定义顺序栈类型,用于描述停车场
typedef struct
{
int CarNo[M]; //车牌号
int front,rear; //队首和队尾指针
} SqQueue; //定义循环队类型,用于描述候车场
//以下为顺序栈的基本运算算法
void InitStack(SqStack*s)
{
s->top=-1;
}
int StackEmpty(SqStack *s)
{
return(s-> top == -1);
}
int StackFull(SqStack *s)
{
return(s->top ==N-1);
}
int Push(SqStack *s, int e1,int e2)
{
if (s->top==N- 1)
return 0;
s->top ++;
s -> CarNo[s -> top] = e1;
s->CarTime[s->top]=e2;
return 1;
}
int Pop(SqStack*s, int *e1,int *e2)
{
if (s->top == 1)
return 0;
*e1 = s -> CarNo[s-> top];
*e2 = s -> CarTime[s -> top];
s->top--;
return 1;
}
void DispStack(SqStack *s)
{
int i;
for(i=s->top;i>=0; i--)
printf("\n\t\t\t%-6d%-6d",s->CarNo[i],s->CarTime[i]);
printf("\n");
}
//以下为循环队列的基本运算算法
void InitQueue(SqQueue *q)
{
q->front=q-> rear =0;
}
int QueueEmpty(SqQueue *q)
{
return (q -> front == q -> rear);
int QueueFull (SqQueue *q) //判断队满
{
return ((q -> rear + 1)% M == q -> front);
}
int enQueue(SqQueue *q, int e) //进队
{
if ((q -> rear + 1)% M == q -> front) //队满
return 0;
q -> rear = (q -> rear + 1)% M;
q -> CarNo[q -> rear] = e;
return 1;
}
int deQueue (SqQueue *q, int *e) //出队
{
if (q-> front == q -> rear) //队空情况
return 0;
q-> front = (q -> front + 1)% M;
*e = q-> CarNo[q -> front];
return 1;
}
void DispQueue(SqQueue *q) //输出队中元素
{
int i;
i = (q -> front + 1)% M;
printf("%d ", q-> CarNo[i]);
while ((q -> rear - i + M)% M > 0)
{
i = (i + 1)%M;
printf(" \n% d ", q-> CarNo[i]);
}
printf(" \n");
}
//main 函数用于模拟停车场的工作
int main()
{
int comm;
int no, e1, time, e2;
int i, j, t;
SqStack stop, away;
//St 是停车场,St1 是在有车离开时,记录为该车移开位置的车辆
SqStack * St = &stop, * St1 = &away;
SqQueue hcar; //hcar 是候车场
SqQueue *Qu = &hcar;
InitStack(St);
InitStack(St1);
InitQueue(Qu);
do
{
printf("\n\n\n\t\t请选择:\n");
printf("\t\t1:到达\n");
printf("\t\t2:离开\n");
printf("\t\t3:显示停车场\n");
printf("\t\t4:显示候车场\n");
printf("\t\t0:退出\n");
scanf("%d",&comm);
system("cls");
switch(comm)
{
case 1: //有车到达
printf("\n\t\t输入车号和进入时间(注意均为整数):");
scanf("%d%d",&no,&time);
if(!StackFull(St))
{
Push(St,no,time);
printf("\n\t\t >>您的车辆停在第:%d号车位\n",St->top+1);
}
else //停车场满
{
if(!QueueFull(Qu)) //候车场不满
{
enQueue(Qu,no);
printf("\n\t\t\t>>您的车辆停放在停车场的位置为:%d\n",Qu->rear);
}
else
printf("\n\t\t >>候车场已满,不能停车\n");
}
break;
case 2: //有车离开
printf("\n\t\t输入车号和离开时间(注意均为整数):");
scanf("%d%d",&no,&time);
for(i=0;i<=St->top && St->CarNo[i]!=no;i++); //在栈中找
if(i>St->top)
printf("\n\t\t >>未找到该编号汽车\n");
else
{
t=St->top-i; //需要出栈的车俩数目
for(j=0;j<t;j++)
{
Pop(St,&e1,&e2);
Push(St1,e1,e2); //倒车到临时栈St1中
}
Pop(St,&e1,&e2); //该汽车离开
printf("\n\t\t >>%d\n本次停车费用:%d\n",no,(time-e2)*Price);
while(!StackEmpty(St1)) //将临时栈St1重新回到St1中
{
Pop(St1,&e1,&e2);
Push(St,e1,e2);
}
if(!QueueEmpty(Qu)) //队不空时,将队头进栈St
{
deQueue(Qu,&e1);
Push(St,e1,time); //以当前时间开始计费
}
}
break;
case 3: //显示停车场情况
if(!StackEmpty(St))
{
printf("\n\t\t >>停车场中的车辆:"); //输出停车场中的车辆
DispStack(St);
}
else
printf("\n\t\t >>停车场中无车辆\n:");
break;
case 4: //显示侯车场中的车辆
if(!QueueEmpty(Qu))
{
printf("\n\t\t >>候车场中的车辆:");
DispQueue(Qu);
}
else
printf("\n\t\t >>侯车场中无车辆\n:");
break;
case 0: //结束
if(!StackEmpty(St))
{
printf("\n\t\t >>停车场中的车辆:"); //输出停车场的车辆
DispStack(St);
}
if(!QueueEmpty(Qu))
{
printf("\n\t\t >>候车场中的车辆:");//输出侯车场的车辆
DispQueue(Qu);
}
break;
default: // 其他情况
printf("\n\t\t >>输入的命令错误\n:");
break;
}
}
while(comm!=0);
return 0;
}
QueueEmpty函数缺}。
212行会不会是死循环?