본문 바로가기

개발공부/C lang3

(c lang) RB-tree(red black tree) 구현 RB-tree insert 함수는 Jenny's lectures CS/IT NET&JRF 유튜브 강의를 참고했습니다 [rbtree insert 유튜브 강의 바로가기] delete 함수는 introduction to algorithms(Thomas H. Cormen 등)을 참고했습니다 tree 구조체 root 노드 포인터를 멤버로 가져 트리 전체를 가리킨다 typedef struct { node_t *root; } rbtree; rbtree *new_rbtree(void) { rbtree *p = (rbtree *)calloc(sizeof(rbtree), 1); return p; }node 구조체 color(red, black), key, parent, left-child, right-child를 .. 2021. 9. 9.
(c lang) binary search tree 구현 introduction to algorithms(Thomas H. Cormen...) 의 수도코드를 강력하게 참고했습니다 node 구조체 구현 // node definition typedef struct node{ int key; struct node *parent; struct node *left; struct node *right; } node_ttree 초기화 node_t형 포인터 초기화 // initialize root node_t *root = NULL; // insert nodes insert(&root, 7); insert(&root, 3); insert(&root, 5); insert(&root, 9); // 7 // / \ // 3 9 // / \ | \ // N 5 N N // / \ .. 2021. 9. 5.
(c lang) linked-list 구현 연결리스트 구현 노드 구현(node_t형 구조체) 노드 구조체는 int 형 val멤버와 다음 노드를 가리키는 node_t형 포인터 next멤버를 갖는다// node definition typedef struct node{ int val; struct node *next; } node_t linked-list 초기화 node_t *head = NULL; node_t형 포인터로 초기화// initialize head(node_t pointer) node_t * head = NULL; print_list함수 print_list(node_t *head); 첫 노드부터 마지막 노드까지 val 멤버를 출력 예외1: 노드가 없는 경우// print out value of all nodes int print_list(.. 2021. 9. 4.