1. 选择排序
void SelectSort(vector<int>& iv)
{
int begin = 0;
int end = iv.size() - 1;
while (begin <= end)
{
int maxi = begin;
int mini = end;
for (int i = begin; i <= end; ++i)
{
if (iv[i] > iv[maxi])
maxi = i;
if (iv[i] < iv[mini])
mini = i;
}
swap(iv[begin], iv[mini]);
if (begin == maxi)
maxi = mini;
swap(iv[end], iv[maxi]);
begin++;
end--;
}
}
2. 冒泡排序
void BubbleSort(vector<int>& iv)
{
for (int i = 0; i < iv.size() - 1; ++i)
{
for (int j = 1; j < iv.size(); ++j)
{
if (iv[j] < iv[j - 1])
{
swap(iv[j], iv[j - 1]);
}
}
}
}