Skip to content

Commit e19b6d0

Browse files
authored
added DFS
1 parent 493c009 commit e19b6d0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Depth-First-Search.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
void visit( int k, int *id, int val[ ], nodePtr adjList[ ] )‏
3+
{
4+
nodePtr t;
5+
*id++;
6+
val[k] = *id;
7+
t = adjList[k];
8+
while (t != NULL)‏
9+
{
10+
if (val[ t->v ] == 0)‏
11+
visit(t->v, id, val, adjList);
12+
t = t -> next;
13+
}
14+
}
15+
16+
void dfs( nodePtr adjList[ ], int n )‏
17+
{
18+
int k, id;
19+
int val[1..MAX] = { 0 };
20+
id = 0;
21+
for (k = 0; k < n; k++)‏
22+
if (val(k) == 0)‏
23+
visit(k, &id, val, adjList);
24+

0 commit comments

Comments
 (0)