DFS - visited[i]=FALSE; for(i=0;i<n;i++) if(!visited[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> #define MAX 10 #define FALSE 0 #define TRUE 1 /* RISHI AGARWAL          DFS TRAVERSAL    ROLL NO 02    SE CMPN A */ 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; n=G.size; for(i=0;i<n;i++)
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: visited[i]=FALSE; for(i=0;i<n;i++) if(!visited[i]) DFS_search(i); } void DFS_search(int visited_no) {int j; visited[visited_no]=TRUE; printf("\nNode %d visited\n",visited_no+1); for(j=0;j<G.size;j++) if(G.a[visited_no][j] != 0 && !visited[j]) DFS_search(j); } void main() { clrscr(); DFS_trav(); DFS(); getch(); } 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

This note was uploaded on 10/25/2010 for the course CMPN SEM4 taught by Professor Thakur during the Spring '07 term at University of Mumbai.

Page1 / 2

DFS - visited[i]=FALSE; for(i=0;i<n;i++) if(!visited[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