輸入:未排序數序列
輸出:排序過後序列
最差時間複雜度 О(n²)
最優時間複雜度 О(n²)
平均時間複雜度 О(n²)
#include <stdio.h>
void soft(int a[], int length){
for(int i = 0; i < length-2; i++){
int min = i;
for(int j = i + 1; j < length; j++){
if(a[j]< a[min])
{
int temp = a[j];
a[j] = a[min];
a[min] = temp;
}
}
}
for(int i=0; i<length;i++){
printf("%d\n", a[i]);
}
}
int main(){
int A[] = {98, 45, 68, 90, 29, 43, 17};
int length = sizeof(A)/sizeof(int);
soft(A,length);
return 1;
}
