# include
100//# define MaxVertices hypothesis contains 100 vertices
# define//no adjacency MaxWeight 65535 to 65535, but with the output of the "up"
Typedef struct {//contains right of adjacency matrix of the definition of
Int are [MaxVertices];//array of vertex information
Int Edge [MaxVertices] [MaxVertices];//the edge of the right to information array
Int numV;//the current vertex
Int numE;//the number of edges
} AdjMatrix;
Typedef struct ANode
{
Int adjvex;
Struct ANode * nextarc;
//infotypes info;
} ArcNode;
Typedef struct Vnode
{
The int data;
ArcNode * firstarc;
} VNode.
Typedef VNode AdjList [MaxVertices];
Typedef struct
{
AdjList AdjList;
Int numv nume;
} ALGraph;
Void MatToList (AdjMatrix G, ALGraph * G)
{
Int I, j, numv=G.n umV;
ArcNode * p;
G=(ALGraph *) malloc (sizeof (ALGraph));
for (i=0; I & lt; Numv; I++)
G - & gt; Adjlist [I] firstarc=NULL;
for (i=0; I & lt; Numv; I++)
For (j=numv - 1; J & gt;=0; J -)
If (G.E dge [I] [j].=0)
{
P=(ArcNode *) malloc (sizeof (ArcNode));
P - & gt; Adjvex=j;
P - & gt; Nextarc=g - & gt; Adjlist [I] firstarc;
G - & gt; Adjlist [I] firstarc=p;
}
G - & gt; Numv=G.n umV; G - & gt; Nume=G.n umE;
}
Void CreateGraph (AdjMatrix * G)//graph generating function
{
Int n, e, vi, vj, w, I, j;
//printf (" please enter the figure on the number of vertices and edges (separated by Spaces) : ");
//the scanf (" % d % d ", & amp; N, & amp; e);
N=6;
E=10;
G - & gt; NumV=n; G - & gt; NumE=e;
for (i=0; I & lt; n; I++)//figure initialization
For (j=0; J & lt; n; J++)
{
If (I==j)
G - & gt; Edge [I] [j]=0;
The else
G - & gt; Edge [I] [j]=MaxWeight;
}
/* for (I=0; I
Printf (" please enter the first vertex information % d (integer) : ", I + 1);
The scanf (" % d ", & amp; G - & gt; Are [I]);
} */
G - & gt; Are [0]=0;
G - & gt; Are [1]=1;
G - & gt; Are [2]=2;
G - & gt; Are [3]=3;
G - & gt; Are [4]=4;
G - & gt; Are [5]=5;
//printf (" \ n ");
/* for (I=0; I
Printf (" please enter the article % d information on the side of I, j, w (separated by Spaces) : ", I + 1);
The scanf (" % d % d % d ", & amp; Vi, & amp; Vj, & amp; W);
//if the figure without weights, the w input 1
//if the weighted value of graphs, the w input corresponding weights
G - & gt; Edge [vi] [vj]=w;//(1)
//G - & gt; Edge [vj - 1]] [vi - 1=w;//(2)
//undirected graph with the rule of symmetry, by (1) (2)
//directed graph does not have this property, so only need to 1)
} */
G - & gt; Edge [0] [1]=5;
G - & gt; Edge [1] [2]=4;
G - & gt; The Edge [2] [0]=8;
G - & gt; Edge [0] [3]=7;
G - & gt; Edge [3] [2]=5;
G - & gt; The Edge [2] [5]=9;
G - & gt; Edge [5] [4]=1;
G - & gt; Edge [4] [3]=5;
G - & gt; Edge [3] [5]=6;
G - & gt; Edge [5] [0]=3;
}
Void printGraph (ALGraph g)
{
int i;
ArcNode * p;
Printf (" output graph adjacency list is: ");
for (i=0; I & lt; G.n umv; I++)
{
Printf (" \ n % 4 d ", g.a djlist [I] data);
P=g.a djlist [I] firstarc;
while (p !=NULL)
{
Printf (" -- -- & gt; % d ", p - & gt; Adjvex);
P=p - & gt; Nextarc;
}
}
printf("\n");
}
Void DispGraph (AdjMatrix G)//output adjacency matrix information
{
Int I, j;
Printf (" \ n output vertex information: \ n ");
for (i=0; I & lt; G.n umV; I++)
Printf (" % d ", G.V ertices [I]);
Printf (" \ n output adjacency matrix: \ n ");
Printf (" \ t ");
for (i=0; I & lt; G.n umV; I++)
Printf (" % d ", G.V ertices [I]);
for (i=0; I & lt; G.n umV; I++)
{
Printf (" \ n % 8 d ", I);
For (j=0; J & lt; G.n umV; J++)
{
If (G.E dge [I] [j]==65535)
Printf (" % s ", "up");
The else
Printf (" % d ", G.E dge [I] [j]);
}
printf("\n");
}
}
Int main ()
{
AdjMatrix G;
ALGraph g;
CreateGraph (& amp; G);
DispGraph (G);
MatToList (G, & amp; G);
PrintGraph (g);
return 0;
}
CodePudding user response:
what is your problemCodePudding user response:
The