11.3中一段伪代码怎样转换为C#代码
 void qsort3(l,u) 
        if (l >= u)
             return
        t = x[1];i = 1;j = u + 1;
        loop
            do i++ while i <= u && array[i] < t
            do j-- while array[j] > t
            if i > j
               break;
            Swap(ref array[i], ref array[j]);
        Swap(ref l, ref j);
        qsort3(l, j - 1);
        qsort3(j + 1, u);c#编程快速排序算法

解决方案 »

  1.   

    void qsort3(int l, int u)
    {
             if (l >= u)
                  return;
             t = x[1];i = 1;j = u + 1;
             while (true)
             {
                 do { i++; } while (i <= u && array[i] < t)
                 do { j--; } while (array[j] > t)
                 if (i > j)
                    break;
                 Swap(ref array[i], ref array[j]);
             }
             Swap(ref l, ref j);
             qsort3(l, j - 1);
             qsort3(j + 1, u);
    }
      

  2.   

    差不多这样吧
      
            int[] x;
            int[] array;        void qsort3(int l, int u)
            {
                int i,j,t;         if (l >= u)
                  return;
             t = x[1];i = 1;j = u + 1;
             while(true)
             {
                 do 
                 {
                     i++;
                 }
                 while (i <= u && array[i] < t);             do
                 {
                     j--;
                 } 
                 while (array[j] > t);             if (i > j)
                    break;             Swap(ref array[i], ref array[j]);
             }
             Swap(ref l, ref j);         qsort3(l, j - 1);
             qsort3(j + 1, u);
            }        private void Swap(ref int i, ref int j)
            {
                int t = i;
                i = j;
                j = t;
            }
      

  3.   

    请教大师,x数组,array数组分别代表什么,哪个是排序前的数组?谢谢您
      

  4.   

    大师,快速排序写好了,您看看
     public void QuickSort(int startIndex, int endIndex)
            {
                if (startIndex >= endIndex)
                {
                    return;
                }
                int m = startIndex;
                for (int i = startIndex + 1; i <= endIndex; i++)
                {
                    if (array[i] < array[startIndex])
                    {
                        Swap(ref array[++m], ref array[i]);//++指向小元素的新位置
                    }
                }
                Swap(ref array[startIndex], ref array[m]);
                QuickSort(startIndex, m - 1);
                QuickSort(m + 1, endIndex);
            }
      

  5.   

    本帖最后由 caozhy 于 2013-01-15 11:09:04 编辑