Home > Back-end >  C language of a topological sort encoding code comments
C language of a topological sort encoding code comments

Time:12-31

Void InitGraph (GraphList * G)/* initialization figure */
{
Int I, vexnum arcnum, weight=0;
Int v1, v2,
EdgeList p;
Printf (" do input the vertexnum and the arcnum - & gt; Form: (x, y) \ n ");
The scanf (" % d, % d ", & amp; Vexnum, & amp; Arcnum);
G - & gt; Vexnum=vexnum;
G - & gt; Arcnum=arcnum;
for(i=0; i{
G - & gt; Vexs [I]. Vertex=I + 1;
G - & gt; Vexs [I] edgelist=NULL;
}
for(i=0; i{
Printf (" do input The % d Edge (For Examp: 1,2,10) \ n ", I + 1);
The scanf (" % d, % d, % d ", & amp; V1, & amp; V2, & amp; Weight);
If (v1 & gt; G - & gt; Vexnum | | v2 & gt; G - & gt; Vexnum)
{
Printf (" The Node You Hava Input Is Not In The Vexs!! ");
getch();
exit(0);
}
P=(EdgeList) malloc (sizeof (EdgeNode));
P - & gt; Endvex=v2;
P - & gt; Weight=weight;
P - & gt; Nextedge=G - & gt; Vexs (v1). Edgelist;
G - & gt; Vexs [v1] edgelist=p;
}
}
  • Related