分享

快速排序

 悟静 2012-02-25
public class QuickSort
       {
           public static void Quicksort(int[] r, int low, int high)
           {
               int pivotLoc = 0;
               if (low < high)
               {
                   pivotLoc = Partition(r, low, high);
                   Quicksort(r, low, pivotLoc - 1);
                   Quicksort(r, pivotLoc + 1, high);
               }
           }
           public static int Partition(int[] r, int low, int high)
           {
 
               int pivot;
               pivot = r[low];
               while (low < high)
               {
                   if (low < high && pivot < r[high])
                   {
                       high--;
                   }
                   r[low] = r[high];
                   if (low < high && r[low] <= pivot)
                   {
                       low++;
                   }
                   r[high] = r[low];
               }
               r[low] = pivot;
               return low;
 
           }
       }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约