Last active
August 29, 2015 14:27
-
-
Save starman3ch/188c23b6f625f366e744 to your computer and use it in GitHub Desktop.
선택 정렬 (C로 구현)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| void SelSort(int arr[], int n) | |
| { | |
| int i, j; | |
| int minIdx; | |
| int temp; | |
| for(i=0; i<n-1; i++) | |
| { | |
| minIdx = i; | |
| for(j=i+1; j<n; j++) // 최소값 탐색 | |
| { | |
| if(arr[j] < arr[minIdx]) | |
| minIdx = j; | |
| } | |
| // 교환 | |
| temp = arr[i]; | |
| arr[i] = arr[minIdx]; | |
| arr[minIdx] = temp; | |
| } | |
| } | |
| int main(void) | |
| { | |
| int arr[4] = {3, 4, 2, 1}; | |
| int i; | |
| SelSort(arr, sizeof(arr)/sizeof(int)); | |
| for(i=0; i<4; i++) | |
| printf("%d ", arr[i]); | |
| printf("\n"); | |
| return 0; | |
| } | |
| // 출처 : 윤성우 자료구조 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment