# Include <stdio. h>
# Include <stdlib. h>
# Include <conio. h>
# Include <string. h>
Int visited [10];/* access flag array */
Typedef struct ArcCell {
Int adj;/* vertex link type. 1 indicates adjacent, 0 indicates not adjacent */
} ArcCell, ** AdjMatrix;/* adjacent matrix */
Typedef struct type {
Char data [3];/* vertex value */
Struct type * next;/* next pointer to the vertex */
} VertexType;
Typedef struct {
VertexType * vexs;/* vertex vector */
AdjMatrix arcs;/* adjacent matrix */
Int vexnum, arcnum;/* Number of vertices and edges of the graph */
} MGraph;
/********************************/
Typedef struct QNode {
Int elem;
Struct QNode * next;
} QNode, * QueuePtr;/* Team data type */
Typedef struct
{QueuePtr front;/* head pointer */
QueuePtr rear;/* Team tail pointer */
} LinkQueue;
Int InitQueue (LinkQueue * Q)/* initialize queue */
{Q-> front = Q-> rear = (QueuePtr) malloc (sizeof (QNode);/* allocate space */
If (! Q-> front) exit (0 );
(Q-> front)-> next = NULL;
Return 1;
}
Int EnQueue (LinkQueue * Q, int e)/* inserted at the end of the queue */
{QueuePtr p;
P = (QueuePtr) malloc (sizeof (QNode);/* allocate space */
If (! P) exit (0 );
P-> elem = e; p-> next = NULL;
(Q-> rear)-> next = p;
Q-> rear = p;/* reset the team end */
Return 1;
}
Int QueueEmpty (LinkQueue Q)/* empty Team */
{If (Q. front = Q. rear) return 1;
Else return 0 ;}
Int DelQueue (LinkQueue * Q, int * e)/* Delete the first element of the queue */
{QueuePtr p;
If (QueueEmpty (* Q) return 0;
P = (Q-> front)-> next;
* E = p-> elem;
(Q-> front)-> next = p-> next;
If (Q-> rear = p) Q-> rear = Q-> front;
Free (p );
Return 1;
}
/**************************/
Void InitGraph (MGraph * G)/* Initial graph */
{Int I, nu, mu;
Printf ("Number of input vertices and number of (edge) arcs :");
Scanf ("% d", & nu, & mu );
G-> arcs = (ArcCell **) malloc (nu * sizeof (ArcCell *));
For (I = 0; I <nu; I ++)/* allocate the adjacent matrix space */
G-> arcs [I] = (ArcCell *) malloc (nu * sizeof (ArcCell ));
G-> vexs = (VertexType *) malloc (nu * sizeof (VertexType);/* allocate vertex space */
G-> vexnum = nu; G-> arcnum = mu;/* Number of vertices and edges */
}
Void InsertGraph (MGraph * G, int I, VertexType e)
{If (I <0 | I> G-> vexnum) return;
G-> vexs [I]. next = e. next;
Strcpy (G-> vexs [I]. data, e. data );