Write A C Program to find the topological ordering of vertices in the given grapgh*/
#include
#include
void main()
{
int p,q,r,vertices,num[10][10],x[10],t[10],calc=0;
printf("Enter the number of vertices: ");
scanf("%d",&vertices);
printf("Enter the Adjacency Matrix:\n");
for(p=1;p<=vertices;p++)
for(q=1;q<=vertices;q++)
scanf("%d",&num[p][q]);
for(p=1;p<=vertices;p++)
x[p]=0,t[p]=0;
for(p=1;p<=vertices;p++)
for(q=1;q<=vertices;q++)
x[p]+=num[q][p];
printf("The Topological order is: \n");
while(calc
for(r=1;r<=vertices;r++)
if((x[r]==0)&&(t[r]==0))
{
printf("%d\t",r);
t[r]=1;
calc++;
for(p=1;p<=vertices;p++)
if(num[r][p]==1)
x[p]--;
}
}
}
/* Output:
Enter the number of vertices: 6
Enter the Adjacency Matrix:
0 0 1 1 0 0
0 0 0 1 1 0
0 0 0 1 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 0
The Topological order is:
1 2 3 4 5 6
...*/
No comments:
Post a Comment