The figure below shows the bus roadmap with only three lines graffiti.
Line 1
A-B-E-D-K
Line 2 F-B-C-D-K-J
Line 3 H-I-E-J-K-D
It is appropriate to save the data structure and use the deformation of the graph.
The first is a collection of all routes. One element contains two identifiers: the route and the first site. You may say that the route needs to be saved twice, because the positive and negative forms are different, because the start site is different. Let's first discuss a situation, that is, from left to right.
Our data set is
(1, A). (2, F), (3, H)
For a site, we need a format for saving information. A single site may have several days of lines together with the next site, so
The site design is as follows:
In addition to saving site information, there are (1, k) (2, K)
The following describes how to obtain the path between two nodes, which is also the core function of the bus query system.
Let's take a few examples (only from left to right ).
1. For example, if I am h now, I think of K. We know that we should be in the current location, and now we set the site You Want To Go To (maybe you don't know the site, you know the location, this can be done by map, map comparison, then you can give the information of the nearby site. This is what we will talk about here ). After entering the site information, when processing the site information, I want the site to have this information, which is on those lines, such as site e on lines 1 and 3.
Next, let's start. Good H is on line 3, and K is on line 3. Good, passengers, you'll take the 3-way car, and you will surely deliver you to K, except the car breaks down halfway.
2. Now we want to go from A to J, which is a little troublesome. Let's enter J. It carries information (2, 3). It seems that we have to switch to another car. No way, we just want to avoid being too pitfall. We got on the road in a, drove a few minutes, arrived at B (), I think I can switch, but not necessarily. I continue to E (), which is also a good choice. But I still don't want to get out of the bus. I will continue to arrive at D. Depending on the situation, you have to take a 3-way car and go back.
Route analysis is as follows:
A-B------J1-2
A-E-J1-3
A-D (k) ---- j1-3
It's just normal, if you're really bored, you can A-B-D-E-J, route: 1-2-1-3, these uninteresting items we should be blocked internally.
Why only discuss one direction, you know how A-K goes, don't you know to K-A?
We will discuss this today.