In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to realize parking lot management in C language, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to realize parking lot management in C language. let's take a look.
1. Problem description
There is only one narrow passageway for n cars in the parking lot, and there is only one gate for cars to enter and exit. Cars in the parking lot are arranged from north to south according to the order of arrival time (the gate is at the southernmost end, and the first car to arrive is parked at the northernmost end of the parking lot). If the parking lot is full of n cars, then the later cars can only wait on the sidewalk outside the door, and once there is a car leaving, the first car on the sidewalk can enter. When a car in the parking lot is about to leave, the vehicle entering after it must first leave the yard to make way for it. When the car leaves the gate, other vehicles will enter the parking lot in the original order. Each car parked in the parking lot must pay a fee according to the length of time it stays when it leaves the parking lot. Try to compile a simulation program for the parking lot to manage according to the above requirements.
2. Basic requirements
The main results are as follows: (1) the parking lot is simulated by stack, the sidewalk outside the parking lot is simulated by queue, and the simulation management is carried out according to the input data sequence read from the terminal.
(2) each set of input data includes three data items: the "arrival" or "departure" information of the car, the license plate number and the time of arrival or departure. The output data after operation on each set of input data is: if the vehicle arrives, then output the parking position of the car in the parking lot or on the service road; if the car leaves Then export the time the car stays in the parking lot and the fee payable (there is no charge for the time spent on the sidewalk).
(3) the stack is implemented in a sequential structure and the queue is implemented in a linked list structure.
(4) Design independently according to the meaning of the topic, and write the design report according to the requirements after the design is finished.
Code block # include # include # include typedef int ElemType;#define MaxSize 100#define QNODE struct QNodetypedef struct Node / / vehicle information {char AL; int NO; int time;} Node;typedef struct Stack / / stack definition {struct Node data [MaxSize]; int top; int num;} SqStack;QNODE / / queue node {struct Node data; QNODE * next;} Typedef struct linkqueue / / queue structure definition {QNODE * front,*rear; int num;} LinkQueue;SqStack * Init_SeqStack () / empty stack {SqStack* s; s = (SqStack*) malloc (sizeof (SqStack)); s-> top=-1; s-> num=0; return s;} LinkQueue * queue () / / create empty queue {LinkQueue * Q QNODE* p; Q = (LinkQueue*) malloc (sizeof (LinkQueue)); p = (QNODE*) malloc (sizeof (QNODE)); p-> next=NULL; Q-> front=q- > rear=p; Q-> num=0; return Q;} int ISEmpty_SeqStack (SqStack * s) / / determines whether the stack is empty, and returns 1 {if (s-> top = =-1) return 1 if the stack is empty Else return 0;} int ISFULL_SeqStack (SqStack * front==q- int n) / / determines whether the stack is full. If the stack is full, return 1 {if (s-> top==n-1) return 1; else return 0;} int ISEmpty_LQueue (LinkQueue * Q) / / to determine whether the queue is empty; if the queue is empty, return 1 {if (Q-> front==q- > rear) return 1; else return 0 } void IN_Lqueue (LinkQueue * Q structure Node s) / / join the queue {QNODE* p; p = (QNODE*) malloc (sizeof (QNODE)); p-> data=s; Q-> num++; p-> next=NULL; Q-> rear- > next= p; Q-> rear = p;} void Push_SeqStack (SqStack * pforce struct Node s) / / join the stack {p-> top + +; p-> data [p-> top] = s P-> num++;} int POP_SeqStack (SqStack * sforce struct Node car) / / stack {SqStack * p; int t; p=Init_SeqStack (); while (s-> data [s-> top]. NO! = car.NO) / / find the car with license plate number P.NO, {Push_SeqStack (pForce s> Data [s-> top]); s-> top--; s-> num-- Time; s-> top--; s-> num--; while (ISEmpty_SeqStack (p) = = 0) {Push_SeqStack (sjournal p-> data [p-> top]); p-> top--; p-> num--;} return t;} struct Node Out_LQueue (LinkQueue * Q) / / out {QNODE * p PairQ-> front- > next; Q-> front- > next=p- > next; Q-> num -; if (Q-> front- > next==NULL) Q-> rear=q- > front; return p-> data; free (p);} int main () {SqStack * parkstack; / / parkstack is the stack LinkQueue * parkqueue; / / parkqueue indicating the parking lot, and the queue struct Node car for the sidewalk Int / n is the maximum capacity of the parking stack float f; / / f is the hourly charge parkstack=Init_SeqStack (); parkqueue=Init_LQueue (); / / initial interface printf ("* parking information query *\ n") Printf ("Please enter the maximum parking capacity n ="); scanf ("% d", & n); printf ("\ nPlease enter the charge per minute f ="); scanf ("% f", & f); printf ("\ nPlease enter vehicle information\ n"); scanf ("% c,% d, & car.AL,&car.NO,&car.time)) While (car.ALBESTRANCHONQ') {if (car.AL=='A') {/ / the arrival of the car if (ISFULL_SeqStack (parkstack,n) = = 1) / / the full stack {IN_Lqueue (parkqueue,car) / / enter the queue and wait for printf ("this car is in position% d on the service road outside the door\ n", parkqueue- > num); printf ("\ n"); printf ("Please enter vehicle information\ n") } else {Push_SeqStack (parkstack,car); / / Stack printf ("this car is in the% d position in the parking lot\ n", parkstack- > num); printf ("\ n") Printf ("Please enter vehicle information\ n");} if (car.AL=='L') / / car departure {t=POP_SeqStack (parkstack,car); / / out-of-stack printf ("this car stays for% d and charges% f. Printf ("\ n"); printf ("Please enter vehicle information\ n"); if (ISEmpty_LQueue (parkqueue) = = 0) / / queue is not empty need to stack Push_SeqStack (parkstack,Out_LQueue (parkqueue)) } if (car.AL=='P'&&car.NO==0&&car.time==0) / / shows the number of vehicles in the parking lot {printf ("number of cars in the parking lot is% d\ n", parkstack- > num); printf ("\ n"); printf ("Please enter vehicle information\ n") } if (car.AL=='W'&&car.NO==0&&car.time==0) / / shows the number of cars in the waiting area {printf ("the number of cars in the waiting area is% d\ n", parkqueue- > num); printf ("\ n"); printf ("Please enter vehicle information\ n") } scanf ("% c _ return% d% d", & car.AL,&car.NO,&car.time);} printf ("input ends\ n"); return 1;} II.
Key words: Amuri arriveth Lmuri Mustang, Pmuri Mustang, Pmuri parkmin, Qmuri quitter, WMI Mui wait.
This is the end of the article on "how to realize parking lot Management in C language". Thank you for your reading. I believe that everyone has a certain understanding of the knowledge of "how to realize parking lot management in C language". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.