정렬2 [C언어] qsort() 로 정렬하기 qsort : 에서 제공하는 Quick Sort 정렬함수 헤더 #include 프로토타입 void qsort (void *base, size_t nel, size_t width, int (*compare)(const void *, const void *) base: 정렬할 배열 nel: 정렬할 배열의 크기 width: 정렬할 배열의 원소 하나의 크기 compare: 비교 기준 함수 compare 함수 int compare(const void *a, const void *b) { if(*(int*)a > *(int*)b) { return 1; } else if(*(int*)a < *(int*)b) { return -1; } else { return 0; } } 적용 예시 arr 정렬하기 #include #.. 2021. 12. 19. 정렬 (Sort) - 선택, 버블, 삽입, 합병, 퀵 전에 정리해둔거.. 다시 정리하기 1. 선택정렬(Selection Sort) void selectionSort(int arr[], int size) { int minIndex;// 최소값의 인덱스 int i, j, temp; for (i = 0; i < size - 1; i++) { minIndex = i; for (j = i + 1; j < size; j++) // arr[i] 이후부터 최소값 찾기 if (arr[j] < arr[minIndex]) minIndex = j; //swap(&arr[i], &arr[minIndex]);// arr[i]와 최소값 자리 바꾸기 temp = arr[minIndex]; // 최솟값을 저장 arr[minIndex] = arr[i]; arr[i] = temp; // 최.. 2021. 10. 2. 이전 1 다음