Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void DFS(int);
- int G[10][10],visited[10],n;
- void main()
- {
- int i,j,v;
- printf("Enter number of total vertices:-");
- scanf("%d",&n);
- printf("\nEnter adjecency matrix of the graph:-\n");
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- scanf("%d",&G[i][j]);
- for(i=0;i<n;i++)
- visited[i]=0;
- printf("Enter the started node:- ");
- scanf("%d",&v);
- DFS(v);
- }
- void DFS(int v)
- {
- int k;
- printf("\n%d",v);
- visited[v]=1;
- for(k=0;k<n;k++)
- if(!visited[k]&&G[v][k]==1)
- DFS(k);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement