DFS - n=G.size; for(i=0;i<n;i++)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> #include<malloc.h> /* RISHI AGARWAL             DFS TRAVERSAL    ROLL NO 02   SE CMPN A*/ #define MAX 10 #define FALSE 0 #define TRUE 1 typedef struct  {int a[MAX][MAX];  int size;}Graph; Graph G; int visited[MAX]; void DFS(); void DFS_search(int visited_no); void DFS_trav() {int i,j,n; printf("\nEnter no of nodes\n"); scanf("%d",&G.size); printf("\nEnter adj matrix\n"); n=G.size; for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&G.a[i][j]); } void DFS() {int i,n;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n=G.size; for(i=0;i&lt;n;i++) visited[i]=FALSE; for(i=0;i&lt;n;i++) if(!visited[i]) DFS_search(i); } void DFS_search(int visited_no) {int j; visited[visited_no]=TRUE; printf(&quot;\nNode %d visited\n&quot;,visited_no+1); for(j=0;j&lt;G.size;j++) if(G.a[visited_no][j] != 0 &amp;&amp; !visited[j]) DFS_search(j); } void main() {DFS_trav(); DFS();} OUTPUT Enter no of nodes 4 Enter adj matrix 0 1 1 1 1 0 0 1 1 0 0 1 1 1 1 0 Node 1 visited Node 2 visited Node 4 visited Node 3 visited...
View Full Document

Page1 / 2

DFS - n=G.size; for(i=0;i&amp;amp;lt;n;i++)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online