选择排序
void Swap(int* p1,int * p2)
{
int tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
void SelectSort(int * a, int n)
{
int left = 0, right = n - 1;
while (left < right)
{
int minIndex = left, maxIndex = right;
for (int i = left; i < right; i++)
{
if (a[i] < a[minIndex])
minIndex = i;
if (a[i] > a[maxIndex])
maxIndex = i;
}
Swap(&a[left], &a[minIndex]);
if (left == maxIndex)
{
maxIndex = minIndex;
}
Swap(&a[right], &a[maxIndex]);
++left;
++right;
}
}