DFS - visited[i]=FALSE for(i=0;i<n;i if!visited[i...

Info icon This 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++)
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern