Created
June 5, 2022 12:31
-
-
Save happyduck-git/71d40330ed8bf74effa4b2ba54a08148 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
public void bFS(int from, int[][] matrix) { | |
Queue<Integer> queue = new LinkedList<>(); | |
boolean[] visited = new boolean[matrix.length]; | |
queue.offer(from); | |
visited[from] = true; | |
while(!queue.isEmpty()) { | |
from = queue.poll(); | |
for(int i = 0; i < matrix[from].length; i++) { | |
if(matrix[from][i] == 1 && !visited[i]) { | |
queue.offer(i); | |
visited[i] = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment