/* 10(b). W.A.P. to obtain Topological ordering of vertices in a digraph */
#include<stdio.h>
#include<conio.h>
void main()
{
int
Tseq[10],count=0,oldcnt=0,top=-1,a[10][10],n,in[10],i,j,k,visited[10];
clrscr();
printf("Enter no. of vertices : ");
scanf("%d",&n);
printf("\nEnter the adjacency matrix :\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
scanf("%d",&a[i][j]);
in[i] =
visited[i] = 0; // Initialize indegree of vertices unvisited
}
for (i = 0; i < n; i++)
in[i]--;
}
if (oldcnt == count) // No topological sequence found
count++;
if (top == n-1)
{
printf("\nTopological sequence is :\n");
for (i = 0; i < n; i++)
printf("%d\t",Tseq[i]);
}
else
printf("\nNo topological ordering in a given
digraph.");
getch();
}
/* OUTPUT
Enter no. of vertices : 3
Enter the adjacency matrix :
0 1 1
0 0 1
0 0 0
The topological sequence is :
1 2 3
Enter no. of vertices : 3
Enter the adjacency matrix :
1 0 0
0 1 1
1 0 1
No topological ordering in a given digraph.
*/