# Bus Line Management

1 Project introduction
This project is a simple simulation of bus route information to complete the functions of building bus route information, modifying bus route information and deleting bus route information.
2 Design Ideas
The essence of this project is to complete the functions of building, finding, inserting, modifying and deleting bus route information. First, you can define the data structure of the project, then write each function as a function to complete the operation of the data, and finally complete the main function to verify each function and get the result of operation.
3 Data structure
The relationship between bus stops can be arbitrary, and any two stops can be related.In a graph structure, the relationship between nodes can be arbitrary, and any two data elements in the graph can be related.So we can use a graphical structure to represent the possible bus routes between n bus stops and between the stops, where the vertices of the network represent the bus stops, the edges represent the routes between the two stops, and the weights given to the edges represent the corresponding distances.
[Complete Code]

```#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#define OK 1
#define ERROR 0
#define MAX_VERTEX_NUM 20

typedef int Status;
typedef char VerTexType;

typedef struct bus
{
char time;	//Departure time
char start;	//Starting Station
char end;	//Terminus
int score;	//Number of stations
struct bus *next;

typedef bus ElemType;

typedef struct LNode
{
ElemType data; // Data Domain
struct LNode *next; //Pointer field

typedef struct ArcNode	//Structure of arcs
{
int adjvex;	//The position of the vertex to which the arc points
struct ArcNode *nextarc;	//A pointer to the next arc
int *info;	//Pointer to information about the arc
}ArcNode;

typedef struct VNode	//Vertex structure
{
VerTexType data;	//Vertex information
ArcNode *firstarc;	//A pointer to the first arc that depends on that vertex

typedef struct	//Construction of Graphs
{
int vexnum,arcnum;  //Current number of vertices and arcs of a graph
int kind;	//Category flags for diagrams
}ALGraph;

Status LocateVex(ALGraph G,int v)//Find the location of vertices
{
int i;
for(i=0;i<G.vexnum;i++)
{
if(i==G.vertices[i].data)
return i;
}
}

{
ArcNode *p,*q;
int i,j,k,v1,v2;
printf("\n Please enter the total number of locations and routes:");
scanf("%d %d",&G.vexnum,&G.arcnum);
printf("Please enter the name of each place:");
for(i=0;i<G.vexnum;i++)
{
scanf("%d",&G.vertices[i].data);
G.vertices[i].firstarc=NULL;	//Initialization
}
printf("Please enter the starting and ending stations;\n");
for(k=0;k<G.arcnum;k++)
{
scanf("%d %d",&v1,&v2);
i=LocateVex(G,v1);j=LocateVex(G,v2);	//Location
p=(ArcNode*)malloc(sizeof(ArcNode));	//Request a Node
p->nextarc=G.vertices[i].firstarc;	//Connecting Nodes
G.vertices[i].firstarc=p;	//Connecting Nodes
q=(ArcNode*)malloc(sizeof(ArcNode));
q->nextarc=G.vertices[j].firstarc;
G.vertices[j].firstarc=q;
}
}

{
Node *p;
int n,i,s;
char sch1,sch2,sch3;
scanf("%s%s%s",sch1,sch2,sch3);	//Time, departure, end
scanf("%d",&s);		//Number of stations
strcpy(p->time,sch1);
strcpy(p->start,sch2);
strcpy(p->end,sch3);
p->num=n;
p->score=s;
p->next=h;
h=p;
return h;
}

{
while(L!=NULL)
{
if(L->num==i)
break;
L=L->next;
}
if(L!=NULL)
return L;
else
return NULL;
}

// Insert information about a bus route at position i
{
p=L;
int j=0;
while(p&&j<i-1)
{
p=p->next;
++j;
}
if(!p||j>i-1)    return ERROR;
s=(struct LNode*)malloc(sizeof(LNode));  //Generating new nodes*s
s->data=e;  		//Set the data field of node*s to e
s->next=p->next;  		//Pointing the pointer field of node*e to node ai
p->next=s;  	//Pointing the pointer field of node *p to node *s
return OK;
}

{
if(L!=NULL)
printf("%d",L->num);
printf("-->%s",L->time);
printf("-->%s",L->start);
printf("-->%s",L->end);
printf("-->%d",L->score);
}

void Revise(Linklist L,int i)//Modify bus information
{
int choose1,y,a,b;
char sch;
Node *p=GetElem(L,i);
printf("%d Bus No. 1 has the following information:\n",i);
PutPoint(p);
printf("\n Please enter what you want to modify:\n");
printf("2,Departure time\n");
printf("3,Starting Station\n");
printf("4,Terminus\n");
printf("5,Number of stations\n");
scanf("%d",&choose1);
while(choose1)
{
if(choose1==1)
{
scanf("%d",&y);
p->num=y;
printf("Information modification complete\n");
break;
}
if(choose1==2)
{
scanf("%s",sch);
strcpy(p->time,sch);
printf("Information modification complete\n");
break;
}
if(choose1==3)
{
printf("Please enter a new starting point\n");
scanf("%s",sch);
strcpy(p->start,sch);
printf("Information modification complete\n");
break;
}
if(choose1==4)
{
scanf("%s",sch);
strcpy(p->end,sch);
printf("Information modification complete\n");
break;
}
if(choose1==5)
{
printf("Please enter a new number of stations\n");
scanf("%d",&y);
p->score=y;
printf("Information modification complete\n");
break;
}
}
}

{
p=p1=L1=L2=L;
int k=0,x=0;
while(p1!=NULL)
{
k++;
p1=p1->next;
}
if(k==1)
{
p1=NULL;
return p1;
}
else if(L->num==n)
{
L=L->next;
return L;
}
while(L->next->num!=n)
{
x++;
L=L->next;
}
if(x==k-1)
{
L->next=NULL;
return p;
}
else
{
Node *q;
while(L1->next->num!=n)
L1=L1->next;
q=L1->next;
L1->next=q->next;
free(q);
return L2;
}
}

Status Putlist(Linklist L)	//Output Chain Table Content
{
if(L==NULL)
{
printf("No bus route!!\n");
return 0;
}
while(L)
{
printf("%d",L->num);
printf("-->%s",L->time);
printf("-->%s",L->start);
printf("-->%s",L->end);
printf("-->%d",L->score);
printf("\n");
L=L->next;

}
}

//User Interface
int main(void)
{
int x,y,k;
Node *p;
ALGraph G;
CreateUDG(G);
printf("\n******Welcome to Bus Information System******\n");
printf("******* 1,message creation*******\n");
printf("******* 2,Query Information*******\n");
printf("******* 3,Modify Information*******\n");
printf("******* 4,Delete Information*******\n");
printf("******* 5,display information*******\n");
printf("******* 0,Sign out*******\n");
int n,choose2=-1;
while(choose2!=0)
{
printf("\n Enter the serial number before the feature you want to select:");
scanf("%d",&choose2);
if(choose2==0)
break;
else if (choose2==1)
{
printf("\n Please enter the information you want to add as follows:->Departure time->Starting Station->Terminus->Sequential input of station number\n");
//for(k=0;k<G.arcnum;k++)
L1=CreateList(L1);
}
else if(choose2==2)
{
printf("\n Please enter the number you want to query:");
scanf("%d",&y);
p=GetElem(L1,y);
PutPoint(p);
}
else if(choose2==3)
{
printf("\n Enter the number of the car with which you want to modify the information:");
scanf("%d",&y);
Revise(L1,y);
}
else if(choose2==4)
{
printf("\n Please enter the number you want to delete:");
scanf("%d",&y);
L1=DeleteList(L1,y);
printf("Delete successful!\n");
}
else if(choose2==5)
{
printf("The information for the bus route is:\n");
Putlist(L1);
}
}
return 0;
}
```

The program is not so concise, what need to guide me, welcome to harass oh!
Finally, I wish you all a Happy New Year!Happy and healthy!  Thirty-five original articles were published. 8 were praised. 10,000 visits+

Keywords: network