如何去理解 < 拓扑排序算法 >
void Topo_Sort (AlGraph *G)int top = -1;
for (i=0;i<n;i++)
{ if ( G->adjlist[i]. Count = = 0)
{ G->adjlist[i].count = top;
top = i;
}
}
for (i=0;i<n;i++)
{ if (t0p= -1)
{printf(“The network has a cycle”);
return;
}
j=top;
top=G->adjlist[top].count;
printf(“% c”,G->adjlist[j].vertex);
ptr=G->adjlist[j].firstedge;
while (ptr!=null)
{ k=ptr->adjvex;
G->adjlist[k].count--;
if(G->adjlist[k].count= =0)
{G->adjlist[k].count =top;
top=k;
}
ptr=ptr->next;
}
}
}