停车场车位控制 求一简单的程序

[复制链接]
查看11 | 回复0 | 2008-1-2 23:17:11 | 显示全部楼层 |阅读模式
去年我们也做了,要不要把做好的课程设计直接发给你啊!给我200分!!!哈哈吼!#include "stdio.h"#define N 3#define PAY 5#define NULL 0typedef struct{int num;int time;}car;typedef struct{car *base;car *top;int stacksize;}stack;typedef struct QNode{int num;struct QNode *next;}QNode,*Queueprt;typedef struct{Queueprt front;Queueprt rear;}LinkQueue;stack s1,s2;LinkQueue Q;void Initstack12(){s1.base=(car*)malloc(N*sizeof(car));s1.top=s1.base;s1.stacksize=N;s2.base=(car*)malloc(N+sizeof(car));s2.top=s2.base;s2.stacksize=N;}void Initqueue(){Q.front=(Queueprt)malloc(sizeof(QNode));Q.rear=Q.front;}int arrive2(int num){Queueprt p,q=Q.front->next;int f=1;while(q){if(q->num==num)f=0;q=q->next;}if(!f) return f;else {
p=(Queueprt)malloc(sizeof(QNode));
p->num=num;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
printf("NO.%d arrive at the biandao.\n",num);
return f;
}}int arrive1(int num,int time){int f=1;car *c=s1.base;while(cnum==num)f=0;c++;}if(!f)return f;else {if(s1.top-s1.basenum=num;s1.top->time=time;s1.top++;printf("NO.%d goes into the park\n",num);return f;
}else
{f=arrive2(num);return f;
}
}}int depart2(int num){Queueprt p,q;int f=0;p=Q.front->next;q=Q.front;while(p->num!=num&&qnext;q=q->next;}if(q==Q.rear)return f;else{
q->next=p->next;
if(p==Q.rear)Q.rear=q;
free(p);
printf("NO.%d depart biandao\n",num);
f=1;
return f;
}}int depart1(int num,int time){int a,f=1;car *c,e;Queueprt p;c=s1.base;while(c->num!=num&&c=s1.top){
if(Q.front==Q.rear)return 0;
else{f=depart2(num);return f;}}else{
a=(time-(c->time))*PAY;
if(ac)
{
s2.top->num=s1.top->num;
s2.top->time=s1.top->time;
s2.top++;
} while(s2.top!=s2.base)
{s2.top--;
s1.top->num=s2.top->num;
s1.top->time=s2.top->time;
s1.top++;
}
printf("NO.%d depart the park!Pay $%d.\n",num,a); if(Q.rear!=Q.front)
{p=Q.front->next;
a=p->num;
Q.front->next=p->next;
if(Q.rear==p)Q.rear=Q.front;
free(p);
e.num=a;
e.time=time;
*s1.top++=e;
printf("NO.%d goes from biandao into the park.\n",a);
}return f;
}}}void show(){car *c;Queueprt p;c=s1.base;p=Q.front->next;if(c==s1.top)printf("No cars in the park!");else{ printf("Cars in the park:\n");
while(cnum,c->time);
c++;
}}if(Q.front==Q.rear)printf("NO cars in biandao\n");else{ printf("Cars in the biandao:\n");
while(p)
{printf("NO.%d\n",p->num);
p=p->next;
}}}main(){char a;int num,time;int f;Initstack12();Initqueue();show();a=0;while(a!=69){f=1;do{
printf("Input 'A'or'D'or'E',num and time.\n");
scanf("%c %d %d",&a,&num,&time);
getchar();
if(a==65)
{f=arrive1(num,time);
if(f!=1)printf("There is a same num!!!Please input again!\n");
}
else if(a==68)
{
f=depart1(num,time);
if(f==-1)printf("Time is wrong!!!Please input again!\n");
if(f==0)printf("No this num!!!Please input again!\n");
}
else if(a!=65&&a!=68&a!=69)
{f=0;
printf("ERROR!!!Please input again!\n");
}
} while(f!=1&&a!=69);show();}printf("THE END!\n");}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行