본문 바로가기

전체 글

링크드리스트의 모든 것 linked list 작성중.................... #include /////////////////////////////////single linked list /* head를 기준으로 head에 계속 update하는 것. //stack 같은거 구현 시 용이 함 . 이 때는 count라는 변수를 두어서 pop시 에러처리 해줄 수 있음. // head = head->next struct Node { int data; Node *next; }; Node buf[10000]; int bufCnt; Node *head; Node *myAlloc(int data, Node *next) { buf[bufCnt] = { data, next }; return &buf[bufCnt++]; } void myAlloc(int dat.. 더보기
머지소트(merge sort) Merge sort은 'divide and conquer(분할정복)'의 대표적인 알고리즘이다. 분할 정복 알고리즘(Divide and conquer algorithm)은 그대로 해결할 수 없는 문제를 작은 문제로 분할하여 문제를 해결하는 방법이나 알고리즘이다. (출처: https://ko.wikipedia.org/wiki/%EB%B6%84%ED%95%A0_%EC%A0%95%EB%B3%B5_%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 분할 정복 알고리즘 - 위키백과, 우리 모두의 백과사전 위키백과, 우리 모두의 백과사전. 분할 정복 알고리즘(Divide and conquer algorithm)은 그대로 해결할 수 없는 문제를 작은 문제로 분할하여 문제를 해결하는 방법이나 알고리즘이다... 더보기
배열이용하여 Hash 사용하기(feat. 코딩테스트) 배열을 이용하여 memory 를 잡아준 뒤, Single Linked List로 hash를 사용하는 코드이다. #define MAX_TABLE_SIZE 1000 typedef struct Node { char data[5]; struct Node *prev; } Node; Node a[MAX_TABLE_SIZE]; Node *hashTable[MAX_TABLE_SIZE]; int arr_idx = 0; unsigned long myHash(const char *str) { unsigned long hash = 5381; int c; while (c = *str++) hash = (hash * 7 * c) % MAX_TABLE_SIZE; return hash; } Node* myAlloc(void) { r.. 더보기