AOV图的拓扑排序伪代码实现:
#include<stdio.h>
bool TopologicalSort(Graph G){
InitStack(S);
int i;
for(i=0;i<G.vexnum;i++)
if(indegree[i]==0)
Push(S,i);
int count = 0;
while(!IsEmpty(S)){
Pop(S,i);
print[count++] = i;
for(p=G.vertices[i].firstarc;p;p=p->nextarc){
v = p->adjvex;
if(!(--indegree[v]))
Push(S,i);
}
}
if(count<G.vexnum)
return false;
else
return true;
}