Created
June 4, 2017 10:48
-
-
Save muhammedeminoglu/8e630298e13f131f069d41689892da2c to your computer and use it in GitHub Desktop.
DFS C Code implementation. This code has been written recursive method. Don't forget matris.txt file. You can change it as you want.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
int Array[6][6]; | |
bool visited[6]; | |
void DFS(int root, bool visited[]) | |
{ | |
int i; | |
visited[root] = true; | |
printf("%d ", root); | |
for( i = 0; i < 6; i++) | |
{ | |
if(Array[root][i] == 1 && visited[i] == false) | |
{ | |
DFS(i, visited); | |
} | |
} | |
} | |
void readMatrix() | |
{ | |
int i = 0; | |
FILE *fp = fopen("matris.txt", "r"); | |
while(fscanf(fp, "%d %d %d %d %d %d", | |
&Array[i][0], | |
&Array[i][1], | |
&Array[i][2], | |
&Array[i][3], | |
&Array[i][4], | |
&Array[i][5] | |
) != EOF) | |
{ | |
i = i + 1 ; | |
} | |
} | |
int main() | |
{ | |
readMatrix(); | |
DFS(3, visited); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 1 1 0 0 0 | |
1 0 0 1 0 0 | |
1 0 0 1 0 0 | |
0 1 1 0 1 0 | |
0 0 0 1 0 1 | |
0 0 0 0 1 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment