본문 바로가기

C/알고리즘23

[C] Prim Algorithm 코드 보완 2023.10.06 - [C/알고리즘] - [C] Prim Alogrithm [C] Prim Alogrithm 1. 신장트리 (Spanning Tree): n개의 정점으로 이루어진 무방향 그래프 G에서 n개의 모든 정점과 n-1개의 간선으로 이루어진 트리 : 사이클 발생하면 안됨 사이클 없이 모든 정점 포함하는 트리 1-1. 최 growingupis.tistory.com PriorityQueue.h #include #include #include #include #define MAX_HEAP_SIZE 100 typedef struct _HEAP_NODE_ { int start; int end; int distance; }HEAP_NODE; typedef struct _HEAP_TREE_ { int n; .. 2024. 2. 13.
[C] AVL TREE (코드 보완) 1. AVL TREE 이전 게시물 2023.12.10 - [C/알고리즘] - [C] AVL TREE [C] AVL TREE 1. AVL Tree : 자세한 설명은 아래 글 참조 2023.12.07 - [C++/자료구조] - [C++]AVL Tree [C++]AVL Tree 1. 균형이진탐색트리 (Adelson-Velskii&Landis) : 균형인수(Balance Factor:BF)를 이용하여 트리가 비균형 상태로 되면 growingupis.tistory.com 2. AVL TREE 코드보완 (1) bst delete node 함수 1) 공백 트리인 경우 : 그냥 return if (*node == NULL) { printf("삭제할 노드가 존재하지 않습니다\n"); return; } 2) *node==.. 2024. 2. 12.
[C] 정렬 알고리즘 1. Selection Sort #include #include #include #include #include #define DATASIZE 16 int* generateRand( int , int ); void selectionSort(int* data, int, int); void swap(int*, int*); int main() { int i; int* data = generateRand(100, DATASIZE); printf("\nBefor sorting array\n"); for (i = 0; i < DATASIZE; i++) { printf("%d ", data[i]); } printf("\n"); selectionSort(data, DATASIZE, 1); for (i = 0; i < .. 2024. 2. 12.
[C] 이진 탐색 트리 (BST) bst_func.h #pragma once #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #define TRUE 1 #define FALSE 0 typedef char NodeData; typedef struct _TREENODE_ { NodeData data; struct _TREENODE_* left; struct _TREENODE_* right; }TREENODE; typedef struct _NODEMAP_ { int flag; NodeData data; }NODEMAP; int getMax(int a, int b); int countNode(TREENODE* node); int getHeight(TREENODE* node.. 2024. 2. 8.
[C] 이중 연결 리스트 #define _CRT_SECURE_NO_WARNINGS #include #include #include typedef struct _NODE_ { int data; struct _NODE_* llink; struct _NODE_* rlink; }NODE; typedef struct _LINKED_LIST_ { NODE* head; }LINKED_LIST; LINKED_LIST* createLinkedList() { LINKED_LIST* CL = (LINKED_LIST*)calloc(1, sizeof(LINKED_LIST)); assert(CL != NULL); return CL; } void insertFirstNode(LINKED_LIST* CL, int x) { NODE* newNode = (NO.. 2024. 2. 6.
[C] AVL TREE 1. AVL Tree : 자세한 설명은 아래 글 참조 2023.12.07 - [C++/자료구조] - [C++]AVL Tree [C++]AVL Tree 1. 균형이진탐색트리 (Adelson-Velskii&Landis) : 균형인수(Balance Factor:BF)를 이용하여 트리가 비균형 상태로 되면 스스로 노드들을 재배치하여 균형 상태를 유지하도록 하는 트리 : 평균, 최선, 최악 시 growingupis.tistory.com 2. 구현 2-1. AVL 트리 노드 삭제 (1) 이때 trim 함수에서 루트노드가 바로 삭제노드인 예외 케이스를 고려하여 아래 조건문 추가 if (((*node)->data == item) && *node == avl->root) { BST_Delete(*node, item); .. 2023. 12. 10.