停车场管理代码(帮忙加个注释!)
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define SMAX 2 /*车库容量*/
#define QMAX 10 /*每辆车每时刻的费用*/
typedef struct{
char ad;
int num;
int time;
} ElemType; /*元素类型*/
typedef struct{
ElemType *data;
int top;
} SeqStack; /*顺序栈类型*/
typedef struct{
ElemType *data;
int front,rear;
} SeqQueue; /*顺序队类型*/
typedef struct node{
ElemType data;
struct node *link;
} NodeQueue; /*链队结点类型*/
typedef struct{
NodeQueue *front,*rear;
} LinkQueue; /*链队类型*/
void InitStack(SeqStack *S) /*初始化栈*/
{
S->data=(ElemType*)malloc(SMAX*sizeof(ElemType));
S->top=-1;
}
int SEmpty(SeqStack *S)
{
if(S->top==-1) return 1;
else return 0;
}
int SFull(SeqStack *S)
{
if(S->top==SMAX-1) return 1;
else return 0;
}
int Push(SeqStack *S,ElemType e)
{
if(S->top==SMAX-1) return 0;
S->data[++S->top]=e;
return 1;
}
int Pop(SeqStack *S,ElemType *e)
{
if(S->top==-1) return 0;
*e=S->data[S->top--];
return 1;
}
void InitQueue(SeqQueue *Q)
{
Q->data=(ElemType*)malloc(QMAX*sizeof(ElemType));
Q->front=Q->rear=0;
}
int QEmpty(SeqQueue *Q)
{
if(Q->front==Q->rear) return 1;
else return 0;
}
int EnQueue(SeqQueue *Q,ElemType e)
{
if((Q->rear+1)%QMAX==Q->front) return 0;
Q->data[Q->rear]=e;
Q->rear=(Q->rear+1)%QMAX;
return 1;
}
int DeQueue(SeqQueue *Q,ElemType *e)
{
if(Q->front==Q->rear) return 0;
*e=Q->data[Q->front];
Q->front=(Q->front+1)%QMAX;
return 1;
}
void InitLQueue(LinkQueue *Q) /*初始化便道*/
{
Q->front=Q->rear=NULL;
}
int LQEmpty(LinkQueue *Q)
{
if(Q->front==NULL) return 1;
return 0;
}
int EnLQueue(LinkQueue *Q,ElemType e)
{
NodeQueue *p;
p=(NodeQueue*)malloc(sizeof(NodeQueue));
if(p==NULL) return 0;
p->data=e;
p->link=NULL;
if(Q->front==NULL)
{
Q->front=Q->rear=p;
}
else
{
Q->rear->link=p;
Q->rear=p;
}
return 1;
}
int DeLQueue(LinkQueue *Q,ElemType *e)
{
NodeQueue *p;
if(Q->front==NULL) return 0;
p=Q->front;
Q->front=p->link;
*e=p->data;
free(p);
return 1;
}
void main()
{
SeqStack ST,temp;
LinkQueue Q;
NodeQueue *p,*q;
ElemType x,y;
InitStack(&ST);InitStack(&temp);
InitLQueue(&Q);
scanf("%c %d %d",&x.ad,&x.num,&x.time);
while(x.ad=='A'||x.ad=='D')
{
printf("%c %d %d\n",x.ad,x.num,x.time);
if(x.ad=='A')
{
if(!SFull(&ST))
{
Push(&ST,x);
printf("Arrive in the park:%d\n",ST.top);
}
else
{
EnLQueue(&Q,x);
printf("Arrive in the roadedge:\n");
}
}
else
{
while(!SEmpty(&ST)&&ST.data[ST.top].num!=x.num)
{
Pop(&ST,&y);
Push(&temp,y);
}
if(!SEmpty(&ST))
{
Pop(&ST,&y);
printf("Stop time:%d\n",x.time-y.time);
while(!SEmpty(&temp))
{
Pop(&temp,&y);
Push(&ST,y);
}
}
else
{
if(!LQEmpty(&Q))
{
p=Q.front;
while(p->data.num!=x.num)
{
q=p;
p=p->link;
}
if(p==Q.front)
{
Q.front=p->link;
}
else
{
q->link=p->link;
}
free(p);
}
}
}
scanf("%*c%c %d %d",&x.ad,&x.num,&x.time);
}
}
#include <conio.h>
#include <stdlib.h>
#define SMAX 2 /*车库容量*/
#define QMAX 10 /*每辆车每时刻的费用*/
typedef struct{
char ad;
int num;
int time;
} ElemType; /*元素类型*/
typedef struct{
ElemType *data;
int top;
} SeqStack; /*顺序栈类型*/
typedef struct{
ElemType *data;
int front,rear;
} SeqQueue; /*顺序队类型*/
typedef struct node{
ElemType data;
struct node *link;
} NodeQueue; /*链队结点类型*/
typedef struct{
NodeQueue *front,*rear;
} LinkQueue; /*链队类型*/
void InitStack(SeqStack *S) /*初始化栈*/
{
S->data=(ElemType*)malloc(SMAX*sizeof(ElemType));
S->top=-1;
}
int SEmpty(SeqStack *S)
{
if(S->top==-1) return 1;
else return 0;
}
int SFull(SeqStack *S)
{
if(S->top==SMAX-1) return 1;
else return 0;
}
int Push(SeqStack *S,ElemType e)
{
if(S->top==SMAX-1) return 0;
S->data[++S->top]=e;
return 1;
}
int Pop(SeqStack *S,ElemType *e)
{
if(S->top==-1) return 0;
*e=S->data[S->top--];
return 1;
}
void InitQueue(SeqQueue *Q)
{
Q->data=(ElemType*)malloc(QMAX*sizeof(ElemType));
Q->front=Q->rear=0;
}
int QEmpty(SeqQueue *Q)
{
if(Q->front==Q->rear) return 1;
else return 0;
}
int EnQueue(SeqQueue *Q,ElemType e)
{
if((Q->rear+1)%QMAX==Q->front) return 0;
Q->data[Q->rear]=e;
Q->rear=(Q->rear+1)%QMAX;
return 1;
}
int DeQueue(SeqQueue *Q,ElemType *e)
{
if(Q->front==Q->rear) return 0;
*e=Q->data[Q->front];
Q->front=(Q->front+1)%QMAX;
return 1;
}
void InitLQueue(LinkQueue *Q) /*初始化便道*/
{
Q->front=Q->rear=NULL;
}
int LQEmpty(LinkQueue *Q)
{
if(Q->front==NULL) return 1;
return 0;
}
int EnLQueue(LinkQueue *Q,ElemType e)
{
NodeQueue *p;
p=(NodeQueue*)malloc(sizeof(NodeQueue));
if(p==NULL) return 0;
p->data=e;
p->link=NULL;
if(Q->front==NULL)
{
Q->front=Q->rear=p;
}
else
{
Q->rear->link=p;
Q->rear=p;
}
return 1;
}
int DeLQueue(LinkQueue *Q,ElemType *e)
{
NodeQueue *p;
if(Q->front==NULL) return 0;
p=Q->front;
Q->front=p->link;
*e=p->data;
free(p);
return 1;
}
void main()
{
SeqStack ST,temp;
LinkQueue Q;
NodeQueue *p,*q;
ElemType x,y;
InitStack(&ST);InitStack(&temp);
InitLQueue(&Q);
scanf("%c %d %d",&x.ad,&x.num,&x.time);
while(x.ad=='A'||x.ad=='D')
{
printf("%c %d %d\n",x.ad,x.num,x.time);
if(x.ad=='A')
{
if(!SFull(&ST))
{
Push(&ST,x);
printf("Arrive in the park:%d\n",ST.top);
}
else
{
EnLQueue(&Q,x);
printf("Arrive in the roadedge:\n");
}
}
else
{
while(!SEmpty(&ST)&&ST.data[ST.top].num!=x.num)
{
Pop(&ST,&y);
Push(&temp,y);
}
if(!SEmpty(&ST))
{
Pop(&ST,&y);
printf("Stop time:%d\n",x.time-y.time);
while(!SEmpty(&temp))
{
Pop(&temp,&y);
Push(&ST,y);
}
}
else
{
if(!LQEmpty(&Q))
{
p=Q.front;
while(p->data.num!=x.num)
{
q=p;
p=p->link;
}
if(p==Q.front)
{
Q.front=p->link;
}
else
{
q->link=p->link;
}
free(p);
}
}
}
scanf("%*c%c %d %d",&x.ad,&x.num,&x.time);
}
}
...全文
相关推荐
停车场管理系统课程设计(含详细代码和注释!)
用c++编写的简单的停车场管理系统,里面有c++的详细代码,大家把代码直接拷到vc6.0的.cpp文件中即可使用!保证好用,且原创!
基于java实现停车场管理系统
主要为大家详细介绍了基于java实现停车场管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
停车场管理系统c语言代码及注释
停车场管理系统c语言
c语言程序设计--停车场管理系统
c语言程序设计--停车场管理系统
停车场管理系统需求分析
在停车场管理系统中,系统管理员可以管理操作员和普通用户系统管理员,查看停车场车位的使用状况,进行退出系统,维护系统等功能。


