int edge[][]; //图的邻接矩阵 int in_degree[n]; //顶点的入度 //拓扑排序 void TopoOrder(int n) { int top = -1; for (int i = 0; i < n; ++i) if (in_degree[i] == 0) { in_degree[i] = top; top = i; } for (int i = 0; i < n; ++i) { if(top == -1) { printf("exits backpath/n"); return; } else { int j = top; top = in_degree[top]; for(int k = 1; k <= n; ++k) if(edge[j][k] && (--in_degree[k]) == 0) { in_degree[k] = top; top = k; } } } }