阅读背景:

《数据结构与算法分析(Java语言描述)》读书笔记——图论、哈夫曼树和红黑树

来源:互联网 

1、拓扑排序

void topsort() throws CycleFoundException{
	Queue<Vertex> q = new Queue<>();
	// 序号
	int counter = 0;
	for each Vertex v:
		if(v.indegree == 0)
			q.add(v);
	while(!q.isEmpty()) {
		Vertex v = q.poll();
		v.topNum = ++ counter;
		for each Vertex w adjacent to v :
			if(-- w.indegree == 0)
				q.add(w);
	}
	if(counter != VETICES_NUM)
		throw new CycleFoundException();
}void topsort() throws CycleFoundExcept



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: