110,538
社区成员
发帖
与我相关
我的任务
分享
void QuickSort(int left, int right)
{
do
{
int low = left;
int hi = right;
int median = Array.GetMedian(low, hi);
this.SwapIfGreaterWithItems(low, median);
this.SwapIfGreaterWithItems(low, hi);
this.SwapIfGreaterWithItems(median, hi);
object y = this.keys.GetValue(median);
do
{
try
{
while (this.comparer.Compare(this.keys.GetValue(low), y) < 0)
{
low++;
}
while (this.comparer.Compare(y, this.keys.GetValue(hi)) < 0)
{
hi--;
}
}
catch (IndexOutOfRangeException)
{
throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", new object[] { y, y.GetType().Name, this.comparer }));
}
catch (Exception exception)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), exception);
}
catch
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"));
}
if (low > hi)
{
break;
}
if (low < hi)
{
object obj3 = this.keys.GetValue(low);
this.keys.SetValue(this.keys.GetValue(hi), low);
this.keys.SetValue(obj3, hi);
if (this.items != null)
{
object obj4 = this.items.GetValue(low);
this.items.SetValue(this.items.GetValue(hi), low);
this.items.SetValue(obj4, hi);
}
}
if (low != 0x7fffffff)
{
low++;
}
if (hi != -2147483648)
{
hi--;
}
}
while (low <= hi);
if ((hi - left) <= (right - low))
{
if (left < hi)
{
this.QuickSort(left, hi);
}
left = low;
}
else
{
if (low < right)
{
this.QuickSort(low, right);
}
right = hi;
}
}
while (left < right);
}