int [] a=new int[9] {8,6,3,5,4,9,1,2,7}; 
System.Array.Sort(a);
foreach (int i in a)
  Console.WriteLine(i);

解决方案 »

  1.   

    帮你改了一下:using System; 
    namespace ConsoleApplication7 

     public class Class1 
     { 
      public int [] a=new int[9] {8,6,3,5,4,9,1,2,7}; 
      
      public void quicksort(int h,int t) 
      { 
       if(h<t) 
       { 
        partion(h,t); 
        
       } 
      } 
      //quicksort end 
      public void partion(int h,int t) 
      { 
       int pivot; 
       int i,j; 
       int extr; 
       i=h; 
       j=t; 
       pivot=a[(i+j)/2]; 
       do 
       { 
       while(a[i]<pivot) 
        i++; 
       while(a[j]>pivot) 
        j--; 
        if(i<=j) 
        { 
        if(i != j)
        {
         extr=a[i]; 
         a[i]=a[j]; 
         a[j]=extr; 
        }
         i++; 
         j--; 
        }  
       }while(i<=j); if(i<t)
      quicksort(i,t); 
    if(j>h)
        quicksort(h,j); 
      }   public void writea() 
      { 
       int a1; 
       for(a1=0;a1<=8;a1++) 
        Console.WriteLine("the array is {0}",a[a1]); 
      } 
     } 
     /// <summary> 
     /// Class1 的摘要说明。 
     /// </summary> 
     public class MainClass 
     { 
      /// <summary> 
      /// 应用程序的主入口点。 
      /// </summary> 
      [STAThread]      //partion end 
      static void Main(string[] args) 
      { 
      Class1 doit=new Class1(); 
      doit.quicksort(0,8); 
      doit.writea(); 
      Console.Read(); 
      } 
     } 

      

  2.   

    C#下的System.Array.Sort()就是快速排序啊。
      

  3.   

    using System; 
    namespace ConsoleApplication7 

     public class Class1 
     { 
    public static void QuickSort (int[] intArray, int nLower, int nUpper)
        {
            if (nLower < nUpper)
            {
                int nSplit = Partition (intArray, nLower, nUpper);
                QuickSort (intArray, nLower, nSplit - 1);
                QuickSort (intArray, nSplit + 1, nUpper);
            }
        }    static int Partition (int[] intArray, int nLower, int nUpper)
        {
            int nLeft = nLower + 1;
            int nPivot = intArray[nLower];
            int nRight = nUpper;        int nSwap;
            while (nLeft <= nRight)
            {            while (nLeft <= nRight && intArray[nLeft] < nPivot)
                    nLeft++;            while (nLeft <= nRight && intArray[nRight] >=nPivot )
                    nRight--;
                
                if (nLeft < nRight)
                {
                    nSwap = intArray[nLeft];
                    intArray[nLeft] = intArray[nRight];
                    intArray[nRight] = nSwap;
                    nLeft++;
                    nRight--;
                }
            }        // Move pivot element
            nSwap = intArray[nLower];
            intArray[nLower] = intArray[nRight];
            intArray[nRight] = nSwap;
            return nRight;
        }
     }  public class MainClass 
     { 
    static void Main(string[] args) 

    int[] a= new int[9] {8,6,3,5,4,9,1,2,7}; Class1.QuickSort(a,0,a.Length-1); foreach (int i in a)
    Console.WriteLine(i); Console.ReadLine(); 

     }