본문 바로가기

Coding5

[C] Priority Queue ※ 오름차순 정렬// file: priority_queue.c#include #include #define MAX_SIZE 100struct data { int val;};/* 실제 데이터를 담는 배열 */struct data input[MAX_SIZE];/* 힙은 데이터의 포인터만을 담는 배열 */struct data* heap[MAX_SIZE];int heapSize = 0;void heapInit(void){ heapSize = 0;}int heapPush(struct data* node){ if (heapSize >= MAX_SIZE) { printf("queue is full!"); return 0; } heap[heapSize] = no.. 2025. 11. 16.
[C] Quick Sort #include #include #define MAX_NUM 100struct data { int val;};struct data input[MAX_NUM];struct data* ptrs[MAX_NUM];int num = 10;void quickSort_ascending(struct data* arr[], int first, int last){ int pivot, i, j; struct data* temp; if (first val val && i val > arr[pivot]->val) j--; if (i val >= arr[pivot]->val && i val val) j--; if (i val); } printf("\n");}int main(void){ for (int i.. 2025. 11. 15.
[C] Heap의 특정 index 값 수정 Heap(Priority Queue)에서 특정 index의 값을 수정하는 방법에 대한 글이다. ​ 아래의 내용을 이해하기 위해서는 "배열을 이용한 Heap 구현"에 대해서 알고 있어야 한다. 아래의 링크에는 Heap에 대한 자세한 설명이 있다. [자료구조] 힙(heap)이란 - Heee's Development Blog Step by step goes a long way. gmlwjd9405.github.io 흔히 알고있는 배열을 이용하여 Heap을 구현한 방법은 아래 코드와 같다. #define MAX_SIZE 100 int heap[MAX_SIZE]; int heap_size = 0; void HeapInit(void) { heap_size = 0; } void GoUp(int index) { int.. 2024. 2. 7.
[C] AVL Tree AVL Tree Binary Tree의 한 종류 Left-Subtree와 Right-Subtree의 균형을 유지 임의의 node의 subtree height 차이는 2이하 BF(Balance Factor) 통해서 Tree 균형 유지 BF = "Left_SubTree_Height" - "Right_SubTree_Height" BF = -1 ~ +1 사이의 값을 유지 Left/Right Rotation과 recursive로 구현 Rotate Operation Balance가 무너진 4가지의 경우 및 수정 방법 (LL, RR, LR, RL) Insert 이진 탐색을 통해서 신규 node를 위치시키고, 4가지 규칙 중 하나를 적용하여 Tree 수정 Delete 지우려는 node의 child 갯수에 따라서 처리 .. 2024. 2. 5.
[C] RB Tree 구현 rb_tree.h /* rb_tree.h */ #ifndef _RB_TREE_H_ #define _RB_TREE_H_ #include typedef struct rb_tree_t rb_tree_t; typedef struct rb_node_t rb_node_t; typedef enum rb_color_e rb_color_e; enum rb_color_e { RED, BLACK, }; struct rb_node_t { void* data; struct rb_node_t* left; struct rb_node_t* right; struct rb_node_t* parent; enum rb_color_e color; }; struct rb_tree_t { struct rb_node_t* root; struct .. 2024. 2. 5.