标签:lib int init type ini code max eof fine
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #define MAX_VERTEX_NUM 20 using namespace std; typedef struct { int arc[MAX_VERTEX_NUM+10][MAX_VERTEX_NUM+10]; int vexnum,arcnum; } Mgraph; int num[MAX_VERTEX_NUM+10]; void init(Mgraph *G) { memset(G->arc,0,sizeof(G->arc)); memset(num,0,sizeof(num)); char ch; scanf("%d,%d",&G->vexnum,&G->arcnum); for(int i=1; i<=G->arcnum; i++) { int a,b; scanf("%d,%d",&a,&b); if(!G->arc[a][b]) { G->arc[a][b]=1; num[b]++; } } } void topo(Mgraph &G) { int T=G.vexnum; while(T--) { int sub=0,i,j; for(i=G.vexnum-1; i>=0; i--)//题目要求栈存储入入度为0的点,这里要逆序遍历 { if(!num[i]) { sub=i; break; } } num[sub]--; if(i==-1) break; else cout<<sub<<" "; for(j=0; j<G.vexnum; j++) { if(G.arc[sub][j]!=0) num[j]--; } } } int main() { Mgraph G; init(&G); topo(G); }
转载于:https://blog.csdn.net/Akatsuki__Itachi/article/details/79855297
标签:lib int init type ini code max eof fine
原文地址:https://www.cnblogs.com/coder-tcm/p/8810270.html