topological sorting

Started by aruljothi, Mar 31, 2009, 11:15 AM

Previous topic - Next topic

aruljothi

#include <stdio.h>
#include <stdlib.h>
# include <math.h>

int main()
{
   int i,j,k,n,a[10][10],indeg[10],flag[10],count=0;
   printf("Enter the no of vertices:");
   scanf("%d",&n);
   printf("Enter the adjacency matrix:
");
   for(i=0;i<n;i++)
      for(j=0;j<n;j++)
         scanf("%d",&a[j]);
      for(i=0;i<n;i++)
      {
         indeg=0;
         flag=0;
      }
      for(i=0;i<n;i++)
         for(j=0;j<n;j++)ss
      indeg=indeg+a[j];
         printf("The topological order is:
");
         while(count<n)
         {
            for(k=0;k<n;k++)
            {
               if((indeg[k]==0) && (flag[k]==0))
               {
                  printf("%d
",(k+1));
                    flag [k]=1;
               }

               for(i=0;i<n;i++)
               {
                  if(a[k]==1)
                     indeg[k]--;
               }

            }
            count++;
         }
         return 0;

}