#include<bits/stdc++.h>
using namespace std;
int main()
{
int i, j, k, c = 0, n;
cout << "Enter The No Of Vertex Number :: ";
cin >> n;
int a[n][n];
cout << "Enter The adjacency Matrix :: \n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin >> a[i][j];
}
}
int indeg[n] = {0}, f[n] = {0};
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
indeg[i] = indeg[i] + a[j][i];
}
while(c < n)
{
for(k=0;k<n;k++)
{
if((indeg[k] == 0) && (f[k] == 0))
{
cout << k+1 << "\n";
f[k] = 1;
}
for(i=0;i<n;i++)
{
if(a[i][k] == 1)
indeg[k]--;
}
}
c++;
}
return 0;
}
using namespace std;
int main()
{
int i, j, k, c = 0, n;
cout << "Enter The No Of Vertex Number :: ";
cin >> n;
int a[n][n];
cout << "Enter The adjacency Matrix :: \n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin >> a[i][j];
}
}
int indeg[n] = {0}, f[n] = {0};
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
indeg[i] = indeg[i] + a[j][i];
}
while(c < n)
{
for(k=0;k<n;k++)
{
if((indeg[k] == 0) && (f[k] == 0))
{
cout << k+1 << "\n";
f[k] = 1;
}
for(i=0;i<n;i++)
{
if(a[i][k] == 1)
indeg[k]--;
}
}
c++;
}
return 0;
}
Comments
Post a Comment