#include <iostream>
#include <vector>
using namespace std;
void dfs(int start,vector<vector <int>> &temp,vector<bool> &check) {
cout << start << endl;
check[start] = true;
for (int i = 0; i < temp[start].size(); i++) {
if (temp[start][i] == 1 && check[i] == false) {
dfs(i, temp, check);
}
}
}
int main() {
vector<vector<int>> temp = {
{0,1,1,0,0,0,0},
{1,0,1,1,1,0,0},
{1,1,0,0,0,1,1},
{0,1,0,0,1,0,0},
{0,1,0,1,0,0,0},
{0,0,1,0,0,0,1},
{0,0,1,0,0,1,0}
};
for (int i = 0; i < temp.size(); i++) {
for (int j = 0; j < temp[i].size(); j++) {
cout << temp[i][j];
}
cout << endl;
}
vector <bool> check(temp.size(), false); // 방문한지 안한지
dfs(0,temp,check);
system("pause");
return 0;
}
0110000
1011100
1100011
0100100
0101000
0010001
0010010
0
1
2
5
6
3
4
'C++ 알고리즘 > 6. 검색 알고리즘' 카테고리의 다른 글
깊이 우선 탐색(DFS) // 프로그래머스 타겟넘버 (0) | 2019.09.03 |
---|---|
깊이 우선 탐색 (DFS) // 스텍 사용 (0) | 2019.09.03 |
너비우선 탐색 (BFS) // 큐 사용해야됨 (0) | 2019.09.03 |
댓글