C언어 선택정렬 구현

(C언어 선택 정렬에서 넘어옴)
인쇄용 판은 더 이상 지원되지 않으며 렌더링 오류가 있을 수 있습니다. 브라우저 북마크를 업데이트해 주시고 기본 브라우저 인쇄 기능을 대신 사용해 주십시오.

1 개요

C언어 선택정렬 구현
#include <stdio.h>
void selection_sort(int a[], int size) {
    int i, j, minidx, temp;
    for(i=0; i<size; i++) {
        minidx = i;
        for(j=i+1; j<size; j++) {
            if(a[minidx] > a[j]) minidx = j;
        }
        temp=a[minidx]; a[minidx]=a[i]; a[i]=temp;
    }
}
int main() {
	int arr[] = {9,1,22,4,0,-1,1,22,100,10};
	int size = sizeof(arr)/sizeof(int);
	selection_sort(arr, size);
	for(int i=0; i<size; i++) printf("%d ", arr[i]);
	// -1 0 1 1 4 9 10 22 22 100 
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}