代码
#include<iostream>
#define N 8
#define ElemType int
/*简单选择排序*/
void SelectSort(ElemType A[], int n) {
int i,j,min,x;
for (i = 0; i < n - 1; ++i) {
min = i;
for (j = i + 1; j < n; j++)
if (A[j] < A[min])
min = j;
if (min != i)
{
x = A[i];
A[i] = A[min];
A[min] = x;
}
}
}
/*输出数组*/
void OutPrint(int A[]) {
int i;
for (i = 0; i < N; i++)
{
printf("%d ", A[i]);
}
}
int main() {
int A[N] = {48, 62, 35, 77, 55,14,35,98 };
printf("排序前数组\n");
OutPrint(A);
SelectSort(A, N - 1);
printf("\n排序后数组\n");
OutPrint(A);
system("pause");
return 0;
}