拓扑排序实现(伪代码)

拓扑排序
void TopologicalSort(Graph G){
	InitStack(S);
	for(i = 0;i < G.vexnum; i++){
		if(indegrdd[i]==0)
			Push(S, i);
	}

	int count =0;
	while(!Empty(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, v);
		}
	}

	if(count < G.vexnum)
		return false;
	else
		return true;
}

    原文作者:拓扑排序
    原文地址: https://blog.csdn.net/u013887008/article/details/49430139
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞