- void toposort(TD g[],int n)
- { int top,m,k,j;
- JD *p;
- top=0; m=0;
- for(j=1;j<=n;j++)
- if(g[j].in==0)
- { g[j].in=top;
- top=j;
- }
- while(top>0)
- { j=top;
- top=g[top].in;
- printf("%dn",j);
- m++;
- p=g[j].link;
- while(p!=NULL)
- { k=p->vex;
- g[k].in--;
- if(g[k].in==0)
- { g[k].in=top;
- top=k;
- }
- p=p->next;
- }
- }
- printf("m=%dn",m);
- if(m<n) printf("The network has a cyclen");
- }