pro8

Document Sample
pro8 Powered By Docstoc
					#include<stdio.h>
#include<conio.h>
void searchfrom(int k);
int n,visited[10],a[10][10];
void main()
{
      int i,j;
      clrscr();
      printf("\n\n\t\t BREADTH FIRST SEARCH");
      printf("\n\n Enter number of vertex     :");
      scanf("%d",&n);
      printf("\n\n Enter the adjacency matrix\n");
      for(i=1;i<=n;i++)
      {
            for(j=1;j<=n;j++)
            {
                  scanf("%d",&a[i][j]);
            }
      }
      printf("\n BREADTH FIRST SEARCH   :");
      for(i=1;i<=n;i++)
            if(visited[i]==0)
                  searchfrom(i);
      getch();
}
void searchfrom(int k)
{
      int i;
      printf("\n%d",k);
      visited [k]=1;
      for(i=1;i<=n;i++)
      {
            if(visited[i]==0)
                  if(a[k][i]!=0)
                  searchfrom(i);
            break;
      }
}

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:1
posted:10/18/2012
language:Latin
pages:1