#include<stdio.h>
void printarry(int a[], int length, int n);
void printarrydetil(int a[], int length, int d);
void printarry(int a[], int length, int n) {
if (n)
printf("经过排序的数:\t");
else
printf("未经过排序的数:\t");
for (int i = 0; i < length - 1; i++)
{
printf("%d\t", a[i]);
}
printf("\n");
}
void printarrydetil(int a[], int length, int d) {
printf("经过第%d轮选择排序的数:", d + 1);
for (int i = 0; i < length - 1; i++)
{
printf("%d\t", a[i]);
}
printf("\n");
}
int main(void) {
int arry[] = { 50,46,89,51,23,65,52,62 };
int length = 8;
int n;
for (int i = 0; i < length - 1; i++)
{
int min;
min = i;
for (int j = i+1; j < length - 1; j++)
{
if (arry[j] < arry[min])
{
min = j;
}
}
if (min != i) {
int t;
t = arry[i];
arry[i] = arry[min];
arry[min] = t;
}
printarrydetil(arry, length, i);
}
n = 1;
printarry(arry, length, n);
return 0;
}