I am a beginner. This is my notebook. There are many flaws in it, which make the experts laugh. Please advise. Contact me QQ 358271030.
This is a parking lot management system simulated by stacks and queues. When a car is registered, it enters the yard. If the parking lot is full, the incoming car enters the driveway and waits. Once a car leaves, the driveway automatically enters the garage.
A stack is used to simulate a parking lot, and a queue is used to simulate an off-site sidewalk.
# Include "stdio. h"
# Define NULL 0
# Define ERROR 0
# Define OK 1
# Define OVERFLOW 0
# Define STACK_INIT_SIZE 2
Typedef struct
{
Char label;
Float time;
} Car, Car2;
Typedef struct
{
Car * top;
Car * base;
Int stacksize;
} SqStack;
Int InitStack (SqStack * S)
{
S-> base = (Car *) malloc (STACK_INIT_SIZE * sizeof (Car ));
If (! (S-> base) return ERROR;
S-> top = S-> base;
S-> stacksize = STACK_INIT_SIZE;
Return OK;
}
Int StackEmpty (SqStack S)
{
If (S. top = S. base)
Return OK;
Else
Return ERROR;
}
Int StackFull (SqStack S)
{
If (S. top-S.base> = STACK_INIT_SIZE)
Return OK;
Else
Return ERROR;
}
Int Push (SqStack * S, Car e)
{
If (S-> top-S-> base> = STACK_INIT_SIZE)
Return OVERFLOW;
Else
{
* (S-> top ++) = e;
Return OK;
}
}
Int Pop (SqStack * S, Car * e)
{
If (S-> top = S-> base)
Return ERROR;
* E = * (-- (S-> top ));
}
Typedef struct
{
Car2 * top2;
Car2 * base2;
Int stacksize2;
} SqStack2;
Int InitStack2 (SqStack2 * S2)
{
S2-> base2 = (Car2 *) malloc (STACK_INIT_SIZE * sizeof (Car2 ));
If (! (S2-> top2) return ERROR;
S2-> top2 = S2-> base2;
S2-> stacksize2 = STACK_INIT_SIZE;
Return OK;
}
Int Push2 (SqStack2 * S2, Car2 e2)
{
If (S2> top2-S2> base2> = STACK_INIT_SIZE)
Return OVERFLOW;
* (S2-> top2 ++) = e2;
Return OK;
}
Int Pop2 (SqStack2 * S2, Car2 * e2)
{
If (S2-> top2 = S2-> base2)
Exit (OVERFLOW );
* E2 = * (-- (S2-> top2 ));
Return OK;
}
Int StackEmpty2 (SqStack2 S2)
{
If (S2.top2 = S2.base2)
Retu