전체 글

요즘 DFS, BFS 문제를 풀고 있는데, 한 번 감이 잡히니까 문제가 계속 잘 풀려서 감사한 마음이 든다. BFS 문제를 풀 때는 Queue를 사용해서 문제를 풀 수 있는데, 내가 초반에 많이 실수 했던 부분은 노드의 방문 기록을 남기는 작업을 하지 않았었다. 이제는 습관을 잡아, 무조건 DFS든 BFS든 visited 배열을 항상 만들고 시작한다. 아래 문제는 전형적인 BFS 문제인데, 이 문제에서 핵심은 수빈이가 동생을 찾기 위한 방법이 3가지라는 것이다. 방법 1. 현재 위치 - 1 방법 2. 현재 위치 + 1 방법 3. 현재 위치 x 2 나 같은 경우는 보통 DFS, BFS 문제를 풀 때, 구조체를 활용해서 움직이는 객체를 생성한다. queue를 생성하고, 초기 위치를 push 해준다. 이 후 ..
인접 리스트 방식 그래프 #pragma once #ifndef GRAPH_H #define GRAPH_H #include #include enum VisitedMode { Visited, NotVisited }; typedef int ElementType; typedef struct tagVertex { ElementType Data; int Visited; int Index; struct tagVertex* Next; struct tagEdge* AdjacenyList; } Vertex; typedef struct tagEdge { int Weight; struct tagEdge* Next; Vertex* From; Vertex* Target; } Edge; typedef struct tagGraph ..
LCRS(Left Child Right Sibling) 트리 #pragma once #ifndef LCRSTREE_H #define LCRSTREE_H #include #include typedef char ElementType; typedef struct tagLCRSNode { struct tagLCRSNode* LeftChild; struct tagLCRSNode* RightSibling; ElementType Data; }LCRSNode; LCRSNode* LCRS_CreateNode(ElementType NewData); void LCRS_DestroyNode(LCRSNode* Node); void LCRS_AddChildNode(LCRSNode* Parent, LCRSNode* Child); ..
#pragma once #ifndef CIRCULAR_QUEUE_H #define CIRCULAR_QUEUE_H #include #include typedef int ElementType; typedef struct tagNode { ElementType Data; }Node; typedef struct tagCircularQueue { int Capacity; int Front; int Rear; Node* Nodes; } CircularQueue; void CQ_CreateQueue(CircularQueue** Queue, int Capacity); void CQ_DestroyQueue(CircularQueue* Queue); void CQ_Enqueue(CircularQueue* Queue, Ele..