[[TableOfContents]] = 예정 = * C언어 문법은 일단 여기까지 * 본격적 알고리즘 시작 * 선형 자료 구조(linear data structure) * 배열(array) : fixed-sized collection of contiguous data * random access * 연결 리스트(linked list) : sequential of data linked by pointer * node - link * array v.s. linked list * algorithms for sequential data * 탐색(search) * 선형 탐색(linear search) * 이진 탐색(binary search) * 정렬(sort) * 선택 정렬(selection sort) * 삽입 정렬(insertion sort) * 병합 정렬(merge sort) * divide-and-conqurer * 퀵 정렬(quick sort) * performance * big-O notation(big-Omega, big-Theta) * speed, time complexity * memory, space complexity, in-place sort * stablity * swap sort v.s. others * e.g) counting sort, radix sort * '''이번주는 일정이 안맞아 휴강; 다음주에 이 내용으로 진행합니다.''' = 진행 = = 실습 = * selection_sort, insertion_sort, merge_sort, quick_sort(,bubble_sort : optional) * {{{ input_file [output_file]}}} * any language * input : * 1st line : # of line N * 2nd ~ : (unsorted) N integers * output: * N line : sorted N integers * N + 1 line : elapsed time (in millisecond) * print in output file; if no argument, to standard output(terminal console) = 과제 = * 창성 {{{ #include #include #include #include #define swap(type,x,y) type t = x; x = y; y = t; //교환함수 void selection(void); //선택정렬 void insertion(void); //삽입정렬 void merge(int,int); //병합정렬 void quick(int,int); //퀵정렬 void bubble(void); //버블정렬 void output(char*); //(output.txt로 정렬된 수열과 elapsed time 출력) or 표준출력 int n; int *a; int *buff; double milsec; time_t start, end; FILE *input_file; FILE *output_file; int main(int argc, char* argv[]){ int i; char num[10]; //n은 1,000,000,000미만. input_file = fopen(argv[2],"r"); output_file = fopen(argv[3],"w"); if(input_file == NULL){; printf("ERROR_InputFile\n"); return 0; }//input_file이 존재하지 않으면 에러 출력. fgets(num,sizeof(num),input_file); n = atoi(num); //배열의 크기 N을 구함. a = calloc(n,sizeof(int)); for(i=0;i0 && a[j-1]>tmp; j--){ a[j] = a[j-1]; } a[j] = tmp; } end = clock(); } //병합정렬 void merge(int left, int right){ start = clock(); if(left x) pr--; if(pl <= pr){ swap(int,a[pl],a[pr]); pl++; pr--; } }while(pl <= pr); if(left < pr) quick(left,pr); if(pl < right) quick(pl,right); end = clock(); }//비재귀적인 방법은 스택을 활용. //버블정렬 void bubble(void){ start = clock(); int i = 0, j; while(ii;j--){ if(a[j]