Simple T-car parking information management system using linked list

Source: Internet
Author: User

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 2//Garage capacity
#define Price 0.05//per car per minute

typedef struct TIME//Time node
{
int hour;
int min;
}time;
typedef struct NODE
{
Char num[10];
Time reach;
Time leave;
}carnode;
typedef struct NODE//Analogue Station
{
Carnode *stack[max+1];
int top;
}seqstackcar;
typedef struct CAR
{
Carnode *data;
struct car *next;
}queuenode;
typedef struct NODE//Analog channel
{
Queuenode *head;
Queuenode *rear;
}linkqueuecar;

void Initstack (Seqstackcar *);
int Initqueue (Linkqueuecar *);
int arrival (Seqstackcar *,linkqueuecar *);
void Leave (Seqstackcar *,seqstackcar *,linkqueuecar *);
void list (Seqstackcar,linkqueuecar);

int main (void)
{
Seqstackcar enter,temp;
Linkqueuecar Wait;
int ch;
Initstack (&enter);
Initstack (&temp);
Initqueue (&wait);

while (1)
{
printf ("|-----------------------------------------------|\n");
printf ("|1.the car arrive|\n");
printf ("|2.the car leave|\n");
printf ("|3.the schedule|\n");
printf ("|4.exit|\n");
printf ("|-----------------------------------------------|\n");
while (1)
{
scanf ("%d", &ch);
if (Ch >= 1 &&ch <= 4)
Break
Else
printf ("\nplease choose:1|2|3|4.");
}
Switch (CH)
{
Case 1:
Arrival (&enter,&wait);
Break
Case 2:
Leave (&enter,&temp,&wait);
Break
Case 3:
List (enter,wait);
Break
Case 4:
Exit (0);
Default
Break
}
}
}

Void Initstack (Seqstackcar *s)
{
int i;
s->top = 0;
for (i = 0; I <= MAX; ++i)
{
S->stack[s->top] = NULL;
}
}
int Initqueue (Linkqueuecar *q)
{
Q->head = (Queuenode *) malloc (sizeof (Queuenode));
if (q->head! = null)
{
Q->head->next = null;
Q->rear = q->head;
return 1;
}
Else
{
return-1;
}
}
Void print (Carnode *p,int)
{
int a1,a2,b1,b2;
printf ("\nplease input the Depart time:/**:* */");
scanf ("%d:%d",& (p->leave.hour),& (p->leave.min));
printf ("\nthe number of the car:");
puts (p->num);
printf ("\nthe time the car arrive:%d:%d", p->reach.hour,p->reach.min);
printf ("\nthe depart time:%d:%d", p->leave.hour,p->leave.min);
A1 = p->reach.hour;
A2 = p->reach.min;
B1 = p->leave.hour;
B2 = p->leave.min;
printf ("\nthe fee:%2.1f Yuan", ((B1-A1) *60+ (B2-A2) *price));
Free (p);
}

int arrival (Seqstackcar *enter,linkqueuecar *w)
{
Carnode *p;
Queuenode *t;
p = (Carnode *) malloc (sizeof (Carnode));
Flushall ();
printf ("\ninput the number of the car (example: Shaanxi A1234):");
Gets (P->num);
if (Enter->top < MAX)
{
Enter->top + +;
printf ("\nthe place of the car", enter->top);
printf ("\nthe time the car arrive:/**:* */");
scanf ("%d:%d",& (p->reach.hour),& (p->reach.min));
Enter->stack[enter->top] = p;
return 1;
}
Else
{
printf ("\ n the car must wait on the sidewalk!") ");
t = (Queuenode *) malloc (sizeof (Queuenode));
T->data = p;
T->next = NULL;
W->rear->next = t;
W->rear = t;
return 1;
}
}
void Leave (Seqstackcar *enter,seqstackcar *temp,linkqueuecar *w)
{
int i,room;
Carnode *p,*t;
Queuenode *q;
if (Enter->top > 0)
{
while (1)
{
printf ("\ n Please enter the location of the car in the yard/1--%d/", enter->top);
scanf ("%d", &room);
if (>= 1 && <= enter->top)
Break
}
while (Enter->top > Guest)
{
Temp->top + +;
Temp->stack[temp->top] = enter->stack[enter->top];
Enter->stack[enter->top] = NULL;
Enter->top--;
}
p = enter->stack[enter->top];
Enter->stack[enter->top] = NULL;
Enter->top--;
while (Temp->top >= 1)
{
Enter->top + +;
Enter->stack[enter->top] = temp->stack[temp->top];
Temp->stack[temp->top] = NULL;
Temp->top--;
}
Print (p,room);
if ((w->head! = w->rear) && Enter->top < MAX)
{
Q = w->head->next;
t = q->next;
Enter->top + +;
printf ("\ n" on the sidewalk's%s car goes to location%d of the yard.) ", t->num,enter->top);
printf ("\ n Please enter the current time/**:* */:");
scanf ("%d:%d",& (t->reach.hour),& (t->reach.min));
W->head->next = q->next;
if (q = = w->rear)
W->rear = w->head;
Enter->stack[enter->top] = t;
Free (q);
}
Else
{
printf ("No car on Sidewalk");
}
}
Else
{
printf ("There's no car in the yard. ");
}
}
void List1 (Seqstackcar *s)
{
int i;
if (S->top > 0)
{
printf ("\ nthe yard:");
printf ("\ n location arrival time license plate number \ n");
for (i = 1; I <= s->top; ++i)
{
printf ("%d", I);
printf ("%d:%d", s->stack[i]->reach.hour,s->stack[i]->reach.min);
Puts (s->stack[i]->num);
}
}
Else
{
printf ("There's no car in the yard. ");
}
}
void List2 (Linkqueuecar *w)
{
Queuenode *p;
p = w->head->next;
if (w->head! = w->rear)
{
printf ("\ n wait for vehicle number:");
while (P! = NULL)
{
Puts (p->data->num);
p = p->next;
}
}
Else
{
printf ("There is no car in the sidewalk." ");
}
}
void list (Seqstackcar s,linkqueuecar W)
{
int Flag,tag;
flag = 1;
while (flag)
{
printf ("\ n Please select 1|2|3:");
printf ("\n1. \n2. Sidewalk \n3. return \ n");
while (1)
{
scanf ("%d", &tag);
if (tag >= 1 | | tag <= 3)
{
Break
}
Else
{
printf ("\ n Please select 1|2|3:");
}
}
Switch (TAG)
{
Case 1:
List1 (&s);
Break
Case 2:
List2 (&AMP;W);
Break
Case 3:
Flag = 0;
Break
Default
Break
}
}
}

Simple T-car parking information management system using linked list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.