
2025.04.19
오늘한 내용 : 고급 자료 구조 :RED-BLACK-TREE 구현
WEEK06: 메모리 누수, 균형 이진 탐색 트리(AVL Tree, Red-Black Tree)
삽입까지 완료! 화이팅
if (p == NULL) return NULL; // 할당 실패시 널 반환(메모리 부족 상태)
node_t *n = malloc(sizeof(node_t));
if (n == NULL) {
free(p); // 닐 노드 실패했으니 rbtree 구조체도 반환해야함!
return NULL;
}
typedef struct node_t {
color_t color;
key_t key;
struct node_t *parent, *left, *right;
} node_t;
typedef struct {
node_t *root;
node_t *nil; // for sentinel
} rbtree;
static void del_node(rbtree *t, node_t* n){ //파일 내부에서만 돌아가는 헬퍼함수
if (n == t->nil){ //끝(nil)이면 그냥 리턴
return ;
}
del_node(t, n->left);
del_node(t, n->right);
free(n);
}
staticstatic