Created
June 5, 2022 11:43
-
-
Save happyduck-git/e1897a4b720e0cdd70719df4527ede3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Recursion 이용한 DFS! | |
public void dFS(int from, int[][] matrix) { | |
boolean[] visited = new boolean[matrix.length]; | |
dFSHelper(from, visited, matrix); | |
} | |
public void dFSHelper(int from, boolean[] visited, int[][] matrix) { | |
//방문 여부 체크 | |
if(visited[from]) return; | |
//첫 방문d이 확인되면 방문 체크! | |
visited[from] = true; | |
//연결된 vertices check | |
for(int i = 0; i < matrix[from].length; i++) { | |
if(matrix[from][i] == 1) { //연결이 되어 있다면 | |
dFSHelper(i, visited, matrix); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment