16,722
社区成员




'实现了icomparer接口
Public Class Comparer
Implements IComparer
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
Dim CC As New CaseInsensitiveComparer()
Return CC.Compare(y, x)
End Function
End Class
'排序
ArrayList.Sort(new Comparer)
internal 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[median];
do
{
try
{
while (this.comparer.Compare(this.keys[low], y) < 0)
{
low++;
}
while (this.comparer.Compare(y, this.keys[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[low];
this.keys[low] = this.keys[hi];
this.keys[hi] = obj3;
if (this.items != null)
{
object obj4 = this.items[low];
this.items[low] = this.items[hi];
this.items[hi] = obj4;
}
}
low++;
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);
}