Сначала я выполняю поиск по глубине, но выходные данные не равны массивам. Что не так?
public static int[] Search (int [][] graph){
boolean[] visited = {false, false, false, false, false, false};
int n = 6;
List<Integer> output = new ArrayList<>();
Search(graph, visited, n, 0);
return output.stream().mapToInt(Integer::intValue).toArray();
}
public static void Search(int[][] graph, boolean [] visited, int n, int i) {
System.out.print((i )+" ");
visited[i] = true;
for (int j = 0; j < n; j++) {
if (!(visited[j]) && graph[i][j] == 1) {
Search(graph, visited, n, j);
}
}
}
public static void main(String[] args) {
int [][] graph={{0,1,1,1,0,0},{1,0,0,0,1,1},{1,0,0,0,0,1},{1,0,0,0,0,0},{0,1,0,0,0,0},{0,1,1,0,0,0}};
int [] Searchresult={0,1,4,5,2,3};
}
Как вы видите, DFSresult и вывод совпадают. Я сделал ошибку в ответном заявлении?