DFS 는 stack 또는 recursive 함수를 사용하여 푼다. BFS 는 queue를 사용하여 푼다. #include #include #include #include #include #include using namespace std; // dfs에 들어오면 '방문'한 것으로 판단 // 해당 위치에 check true 로 해준다. void dfs(int start, vector graph[], bool check[]){ stack s; s.push(start); check[start] = true; printf("%d ", start); while(!s.empty()){ int current_node = s.top(); s.pop(); for(int i = 0; i < graph[current_no..
알고리즘
#include struct CELL{ int s, d, z; }; int r, c, m; CELL map[2][100][100]; int fishing(int cur, int pos){ int size = 0; for(int y = 0; y up // 2 -> down // 3 -> right // 4 -> down void move(int cur){ int next = (cur + 1) % 2; ..
간단하게 재귀함수를 사용하면 쉽게 풀리는 문제 #include using namespace std; int people(int k, int n){ if(k == 0){ return n; } else{ int sum = 0; for(int i = 1; i > t; for(int i = 0; i > k >> n; int sum; sum = people(k, n); cout

링크드 리스트 #ifndef LINKEDLIST_H #define LINKEDLIST_H #include #include typedef int ElementType; typedef struct tagNode{ ElementType Data; struct tagNode* NextNode; }Node; /* 함수 원형 선언 */ Node* SLL_CreateNode(ElementType NewData); void SLL_DestroyNode(Node* Node); void SLL_AppendNode(Node** Head, Node* NewNode); void SLL_InsertAfter(Node* Current, Node* NewNode); void SLL_InsertNewHead(Node**, Node* ..