代码:
using System;
using System.Collections;namespace eTel
{
/// <summary>
/// Class2 的摘要说明。
/// </summary>
public class QuickSort
{
public static int index=0;

QuickSort()
{

}

protected static bool CompareA(ArrayList item1,ArrayList item2)
{
string bs1=item1[index].ToString().Trim();
string bs2=item2[index].ToString().Trim();
if(string.Compare(bs1,bs2)<0)
{
return true;
}
else
{
return false;
}



public static void Sort(ArrayList intArray, int nLower, int nUpper)
{
if (nLower < nUpper)
{
int nSplit = Partition (intArray, nLower, nUpper);
Sort(intArray, nLower, nSplit - 1);
Sort(intArray, nSplit + 1, nUpper);
}
}




     private static int Partition (ArrayList intArray, int nLower, int nUpper)
{
int nLeft = nLower + 1;
int nRight = nUpper; ArrayList nSwap;
ArrayList nPivot =(ArrayList)intArray[nLower];
        
while (nLeft <= nRight)
{ while (nLeft <= nRight && CompareA((ArrayList)intArray[nLeft],nPivot))
nLeft++; while (nLeft <= nRight && !CompareA((ArrayList)intArray[nRight],nPivot))
nRight--;
            
if (nLeft < nRight)
{
nSwap = (ArrayList)intArray[nLeft];
intArray[nLeft] = intArray[nRight];
intArray[nRight] = nSwap;
nLeft++;
nRight--;
}
} // Move pivot element
nSwap = (ArrayList)intArray[nLower];
intArray[nLower] = intArray[nRight];
intArray[nRight] = nSwap;
return nRight;
}

public static void Sort(ArrayList Data)
{
Sort(Data,0,Data.Count-1);
}




}

解决方案 »

  1.   

    Error:
    未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll 中。
      

  2.   

    出错前的部分堆栈跟踪,绝对没有死循环.....
      [<非用户代码>]
    > etel.dll!eTel.QuickSort.CompareA(System.Collections.ArrayList item1 = {Count=47}, System.Collections.ArrayList item2 = {Count=47}) 行22 + 0xa 字节 C#
      etel.dll!eTel.QuickSort.Partition(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6779, int nUpper = 8669) 行62 + 0x2b 字节 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6779, int nUpper = 8669) 行37 + 0xd 字节 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6778, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6777, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6776, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6775, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6774, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6773, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6772, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6771, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6770, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6769, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6768, int nUpper = 8669) 行41 C#
      etel.dll!eTel.QuickSort.Sort(System.Collections.ArrayList intArray = {Count=11413}, int nLower = 6767, int nUpper = 8669) 行41 C#不要和我说,捕获异常后换冒泡在排一遍之类的话.