Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<conio.h>
- #define n 4
- void main()
- {
- int i,j,v,g[n][n],indeg[n],visited[n],count=0;
- printf("Enter the adjacency matrix:\n");
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- scanf("%d", &g[i][j]);
- for(i=0;i<n;i++)
- {
- indeg[i]=0;
- visited[i]=0;
- }
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- indeg[i]=indeg[i]+g[j][i];
- printf("\nThe topological order is:");
- while(count<n)
- {
- for(v=0;v<n;v++)
- {
- if((indeg[v]==0) && (visited[v]==0))
- {
- printf("%d ",v);
- visited[v]=1;
- }
- for(i=0;i<n;i++)
- if(g[i][v]==1)
- indeg[v]--;
- }
- count++;
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment