void SelectSort(int arr[], int length) //每次从待排记录中选择最小的记录,选择排序基于交换式排序
{
if (arr == nullptr || length < 1)
{
return;
}
for (int i = 0; i < length; ++i)
for (int j = i + 1; j < length; ++j)
{
if (arr[j] < arr[i])
swap(arr[j], arr[i]);
}
}
void swap(int &lhs, int &rhs)
{
int tmp = lhs;
lhs = rhs;
rhs = tmp;
}