满意答案
ebcce6021
2014.09.23
采纳率:41% 等级:8
已帮助:414人
class SortManager
{
private int[] a;
private int start;
private int end; public void Sort(int[] a)
{
this.a = a;
start = 0;
end = a.Length - 1; int minIndex = 0;
int maxIndex = 0; while (Result(ref minIndex, ref maxIndex))
{
Move(minIndex, maxIndex); start++;
end--;
}
} private bool Result(ref int minIndex, ref int maxIndex)
{
if (start <= end)
{
int min = a[start];
int max = a[start];
minIndex = maxIndex = start; for (int i = start + 1; i <= end; i++)
{
if (min > a[i])
{
min = a[i];
minIndex = i;
}
else
{
if (max < a[i])
{
max = a[i];
maxIndex = i;
}
}
} return true;
}
else
{
return false;
}
} private void Move(int minIndex, int maxIndex)
{
int temp = a[start];
a[start] = a[minIndex];
a[minIndex] = temp; temp = a[end];
a[end] = a[maxIndex];
a[maxIndex] = temp;
}
}
00分享举报