2016-03-30 12 views
0

Aramak için izin verilen süreleri kontrol etmek istediğim gibi Bu tür bir değişime geçin SelectionSort, heapsort, Quicksort, Mergesort ... Nasıl yazdım? kaç kez çağrı takas yazdırmak için nasıl yorumlarla Hızlı sıralamaOkuma permütasyon sayıları (transpoze sayıları a ve b) saymaya izin verir Böyle Sırala, yığın

public static void Quicksort(int []a,int l,int r) 
    { 
     if (l<r) 
     { 
      int q = Partition(a, l, r); 
      Quicksort(a, l, q - 1); 
      Quicksort(a, q + 1, r); 
     } 
    } 
    public static int Partition(int[] a,int l,int r) 
    { 
     int Dem = 0; 
     int Pivot = a[r]; 
     int i = l; 
     for(int j=l;j<r;j++) 
     { 
      if(a[j]<= Pivot) 
      { 
       XL_SO_NGUYEN.Swap(ref a[j], ref a[i], ref Dem); 
       i++; 
       Dem++; 
      } 

     } 
     a[r] = a[i]; 
     a[i] = Pivot; 

     return i; 
    } 



    public static void Swap(ref int a,ref int b,ref int Count) 
    { 
     int temp =a; 
     a=b; 
     b=temp; 
     Count++; 
    } 

için herkes için geçerlidir aşağıdaki. Sayım == ???

+0

Count baskı ile ne anlama geliyor ... Ne istediğinizi emin? –

cevap

0

Değil

public static int Partition(int[] a,int l,int r) 
    { 
     int Dem = 0; 
     int Pivot = a[r]; 
     int i = l; 
     for(int j=l;j<r;j++) 
     { 
      if(a[j]<= Pivot) 
      { 
       XL_SO_NGUYEN.Swap(ref a[j], ref a[i], ref Dem); 
       i++; 
       Dem++; 
      } 

     } 
     a[r] = a[i]; 
     a[i] = Pivot; 

     // Will write the Count to the output Window 
     // To show "Output Window" ==> Menu - Debug - Windows - Output 
     // Note that you increment Dem in swap and in this function, you sure? 
     Console.WriteLine("Count: " + Dem); 

     return i; 
    }