#include
int length;
void selection_sort(int A[]){
int i,j,min_index;
int min,temp;
for(i=0;i
/*each loop select the minimum number and
move it to the first of the array,
then repeat the step above to the array
that does not include the min number
*/
min=A[i];
min_index=i;
for(j=i+1;j
if(A[j]
min=A[j];
min_index=j;
}
}
if(min_index!=i){
temp=A[i];
A[i]=A[min_index];
A[min_index]=temp;
}
}
}
int main(){
int a[]={3,1,5,12,6,8,11,7,4,15};
length=sizeof(a)/sizeof(a[0]);//get length of a[]
int i;
printf("before:\t");
for(i=0;i
printf("%d ",a[i]);
}
selection_sort(a);
printf("\nafter:\t");
for(i=0;i
printf("%d ",a[i]);
}
getchar();
}