"C언어 선택정렬 구현"의 두 판 사이의 차이

12번째 줄: 12번째 줄:
             if(a[minidx] > a[j]) minidx = j;
             if(a[minidx] > a[j]) minidx = j;
         }
         }
         temp = a[minidx];
         temp=a[minidx]; a[minidx]=a[i]; a[i]=temp;
        a[minidx] = a[i];
        a[i] = temp;
     }
     }
}
}

2018년 8월 26일 (일) 13:14 판

1 개요

C언어 선택정렬 구현
#include <stdio.h>
#define ARRAYSIZE(A) sizeof(A) / sizeof((A)[0])
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 = ARRAYSIZE(arr);
	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 }}