#define _CRT_SECURE_NO_WARNINGS
#include
#include<stdlib.h>
using namespace std;
void choice_sort(int* arr, int length)
{
int i, j, tmp,num;
for ( i = 0; i < length; i++)
{
tmp = i;
for (j = i;j < length;j++)
{
if (arr[j] < arr[tmp])
{
tmp = j;
}
}
num = arr[tmp];
arr[tmp] = arr[i];
arr[i] = num;
}
}
int main()
{
int arr[100];
cout << "please input the length of arr that you want to sort: “;
int n = 0;
cin >> n;
for (int i = 0;i < n;i += 1)
{
cin >> arr[i];
}
choice_sort(arr,n);
for (int i = 0;i < n;i++)
{
cout << arr[i]<<” ";
}
return 0;
}
choice sort
最新推荐文章于 2020-12-12 09:27:42 发布