Home > Back-end >  Data structure, graph traversal)
Data structure, graph traversal)

Time:12-24

Please everyone a great god answers, campus tour consulting return bad 4 item, need to use depth-first traversal and breadth-first traversal (either), I do not how to play up, other code attached, (would be even better shows the code,) thank you!
8. A campus tour guide consulting
Problem description: design a campus tour guide for the school counseling program, meet the following requirements (3), (4) if the result of the use of TC drawing function display, plus 1 minute) :
(1) campus maps stored in the data file format since, at least 15 spots, 25 side), including site number, name, description, information such as the path length between attractions;
(2) according to "scenic spot number/name" query information about any attractions;
(3) after the user specific departure and destination sites, can provide the shortest path between the two attractions information;
(4) can provide users with from designated sites visiting all of the other attractions route information,
[code]=c
 

[/code]The code is as follows: # include "string. H
"# include "stdio.h"
# include "malloc. H"
# include "stdlib. H"
# define Max 20000//edge maximum
16//# define NUM maximum vertex number

Typedef struct ArcCell
{
Int adj.
} ArcCell; Weights, on the edge of deposit//path information,

Typedef struct VertexType
{
int number;
Char * sight;
Char * description;
} VertexType;//store vertex (attraction) information

Typedef struct
{
VertexType vex (NUM);//vertex table
ArcCell arcs [NUM] [NUM];//adjacency matrix
Int vexnum arcnum;//figure on the number of the current vertex and edge
}MGraph;
MGraph G;

Int P [NUM] [NUM];
Long int D (NUM);
Int x [16]={0};
/* function calls */
Void CreateUDN (int v, int a);//the adjacency matrix notation to create undirected network
Void narrate ();//display the attractions menu
Void ShortestPath (int num);//the shortest path
Void the output (int sight1, int sight2);//output the shortest path
Char Menu ();//select menu
Void the search ();//attractions information query function
Char SearchMenu ();//attractions information query menu
Void HaMiTonian (int);
Void NextValue (int);
Void the display ();

Void main ()
{

Int where v0, v1;
Char ck;
CreateUDN (NUM, 11);//the adjacency matrix notation to create undirected network
Do
{
Ck=Menu ();//based on the function of the Menu in the Menu to choose your want
The switch (ck)
{
Case '1' : the search (); break;//query attractions information
Case '2' :
System (" CLS ");
Narrate ();
Printf (" \ n \ n \ t \ \ t t please choose attractions (0 ~ 15) : ");
The scanf (" % d ", & amp; Where v0);
Printf (" \ t \ \ t t please select attractions (0 ~ 15) : ");
The scanf (" % d ", & amp; V1);
ShortestPath (where v0);
The output (where v0, v1);
Printf (" \ n \ n \ \ t \ \ t t t press any key to continue... \n");
getchar();
getchar();
break;
Case '3' :
System (" CLS ");
//narrate ();
X [0]=1;
HaMiTonian (1);
Printf (" \ n \ n \ \ t \ \ t t t press any key to continue... \n");
getchar();
getchar();
break;
};
} while (ck!='e');
}

Char Menu ()
{
Char c;
Int flag;
Do {
Flag=1;
System (" CLS ");
Narrate ();
printf("\n");
Printf (" \ t \ \ t t * * * * * * * * * * * * * * * * * * menu * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ \ t t 1, query attractions \ n ");
Printf (" \ t \ \ t t 2, the shortest path query attractions \ n ");
Printf (" \ t \ \ t t 3, recommend visiting route \ n ");
Printf (" \ t \ \ t t e, exit \ n ");
printf("\n");
Printf (" \ \ t \ \ t t t please enter your choice: ");
The scanf (" % c ", & amp; c);
If (c=='1' | | c=='2' | | c=='3' | | c=='e')
Flag=0;
} while (flag);
Return the c;
}

Char SearchMenu ()//choice is according to scenic spot number or according to the scenic spot name lookup
{
Char c;
Int flag;
Do {
Flag=1;
System (" CLS ");
Narrate ();
Printf (" \ n \ t \ \ t t * * * * * * * * * * * * * * * * * * menu * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t t \ \ t \ n ");
Printf (" \ t \ \ t t 1, according to the spot number query \ n ");
Printf (" \ t \ \ t t 2, according to the scenic spot name lookup \ n ");
Printf (" \ t \ \ t t e, return \ n ");
Printf (" \ t t \ \ t \ n ");
Printf (" \ \ t \ \ t t t please enter your choice: ");
The scanf (" % c ", & amp; c);
If (c=='1' | | c=='2' | | c=='e')
Flag=0;
} while (flag);//when the input 1 or 2 or e flag=0, flag=0 will have a return value, return the corresponding value c, c is the query requirement of the user wants to serial number
Return the c;
}
Void the search ()
{
int num;
int i;
Char c;
char name[20];

Do
{
System (" CLS ");
C=SearchMenu ();//function call, according to the requirements of the users want to query the serial number to choose corresponding function function
The switch (c)
{
Case '1' :
System (" CLS ");
Narrate ();//display the attractions menu
Printf (" \ n \ n \ t \ t to please enter your search sites number: ");
The scanf (" % d ", & amp; Num);
for(i=0; i{
If (num==G.v ex [I] number)
{
Printf (" \ n \ n \ t \ \ t t you want to find spots information is as follows: ");
Printf (" \ n \ n \ t \ \ t \ n \ n "t % 25 s, G.v ex [I] the description).
Printf (" \ n \ t \ \ t t press any key to return... ");
getchar();
getchar();
break;
}
}
If (I==NUM)
{
Printf (" \ n \ n \ t \ \ t t had not found!" );
Printf (" \ n \ n \ t \ \ t t press any key to return... ");
getchar();
getchar();
}

break;
Case '2' :
Narrate ();//display the attractions menu
System (" CLS ");
Printf (" \ n \ n \ t \ t please type in the name of the sites you will find: ");
The scanf (" % s ", name);
for(i=0; i{
if(! STRCMP (name, G.v ex [I] sight))
{
Printf (" \ n \ n \ t \ \ t t you want to find spots information is as follows: ");
Printf (" \ n \ n \ t \ \ t \ n \ n "t % 25 s, G.v ex [I] the description).
Printf (" \ n \ t \ \ t t press any key to return... ");
getchar();
getchar();
break;
}
}
If (I==NUM)
{
Printf (" \ n \ n \ t \ \ t t had not found!" );
Printf (" \ n \ n \ t \ \ t t press any key to return... ");
getchar();
getchar();
}
break;
}
} while (c!='e');
}
Void CreateUDN (int v, int a)//using adjacency matrix notation to create undirected network
{
int i,j;
G.v exnum=v;//figure of the total number of vertices v
G.a rcnum=a; Figure the total number of edges of a//
for(i=0; i{G.v ex [I] number=I; }//storage spots in turn number

/* in turn under the corresponding number to store the name of the attractions and scenic spots information */
G.v ex [0]. Sight="administration building";
G.v ex [0]. The description="school leader, the teacher's office"; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related