I am a beginner in C and have the following exercise:
The Park Parking Here contains a single lane that holds up to ten cars. There is only one entrance / exit in the parking lot, end of the mall. If a customer arrives to pick up a car that not the one closest to the exit, all cars blocking your way out of the parking lot, the customer's car will be out of the parking lot, and the other cars will same initial sequence. Write a program in C that processes a set of inputs. Each entry contains an 'E', entry, or a 'S', output, and the car plate number. It is assumed that cars arrive and depart in the order specified by the entry. The program should print a message whenever a car arrives or leaves. When one car to arrive, the message must specify whether or not there is a car in the parking lot. If there is no vacancy, the car will leave without enter the parking lot. When a car leaves the parking lot, the message should include the number of times the car was maneuvered out of the parking lot to let other cars out.
The push and pop functions seem to be working normally, but when I assign the push function to another (maneuver for example), I can not save to the stack. Here are codes:
struct:
#define 10
struct veiculo
{
int placa;
int manobra;
};
struct pilha
{
struct veiculo item[tamanho];
int topo;
};
push:
void push(struct pilha *pEstacionamento, struct veiculo *carro, int placaDig, int manobraCar)
{
if(pCheia(pEstacionamento))
{
printf("Estacionamento cheio.");
getch();
}
pEstacionamento->topo = pEstacionamento->topo+1;
pEstacionamento->item[pEstacionamento->topo].placa = placaDig;
pEstacionamento->item[pEstacionamento->topo].manobra = manobraCar;
}
struct veiculo pop(struct pilha *pEstacionamento)
{
struct veiculo valor;
if(pVazia(pEstacionamento))
{
printf("Estacionamento vazio");
getch();
valor.placa = -1;
return valor;
}
valor = pEstacionamento->item[pEstacionamento->topo];
pEstacionamento->topo = pEstacionamento->topo - 1;
return valor;
}
Maneuver:
void manobra(struct pilha *pEstacionamento, char status, int placa )
{
struct pilha pEstacionamentoAux;
inicializa(&pEstacionamentoAux);
struct veiculo carro;
int manobraAux;
int placaAux;
if(status == 'e')
{
if(pCheia(pEstacionamento))
{
printf("Estacionamento cheio.");
getch();
}
manobraAux = 0;
//pega o valor da placa e manobra como zero e add na pilha
push(&pEstacionamento, &carro, placa, manobraAux);
}
else if(status == 's')
{
if(pVazia(pEstacionamento))
{
printf("Estacionamento vazio");
getch();
}
while(!pVazia(pEstacionamento))
{
carro = pop(&pEstacionamento->topo);
placaAux = carro.placa;
manobraAux = carro.manobra;
if(placaAux == placa)
{
printf("Seu carro com a placa: %d , foi retirado do estacionamento com %d manobras.", placaAux, manobraAux);
break;
}
else
{
manobraAux = manobraAux + 1;
push(&pEstacionamentoAux, &carro, placaAux, manobraAux);
}
}
while(!pVazia(&pEstacionamentoAux))
{
carro = pop(&pEstacionamentoAux);
placaAux = carro.placa;
manobraAux = carro.manobra;
push(&pEstacionamento, &carro, placaAux, manobraAux);
}
}
If someone can help with any tips on how to proceed, thank you.