Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #define n 4
- int count, visited[n];
- void dfs(int g[n][n],int v)
- {
- int u;
- count=count+1;
- visited[v]=count;
- printf("\n %d",v);
- for(u=0;u<n;u++)
- if(g[v][u]!=0 && visited[u]==0)
- dfs(g,u);
- }
- void DFST(int g[n][n])
- {
- int v;
- count=0;
- for(v=0;v<n;v++)
- visited[v]=0;
- for(v=0;v<n;v++)
- if(visited[v]==0)
- dfs(g,v);
- }
- void main()
- {
- int g[n][n]= {{0,0,1,1},{1,0,0,0},{1,1,0,0},{0,0,0,1}};
- DFST(g);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment