我的快速排序

发布时间:2016-12-6 22:13:35 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"我的快速排序",主要涉及到我的快速排序方面的内容,对于我的快速排序感兴趣的同学可以参考一下。

    private void quickSort(int[] arr,int begin,int end)                {                                                                    if(begin>=end)                                                         return ;                                                                                                                          int low=begin;                                                     int high=end;                                                                                                                         int index=begin;                                                   int temp=arr[begin];                                               boolean flag=false;//当flag的值为true向前,否则向后                           while(low!=high)                                                   {                                                                      if(flag)                                                           {                                                                      for(;low<high;low++)                                               {                                                                      if(arr[low]>temp)                                                  {                                                                      arr[high]=arr[low];                                                high--;                                                            index=low;                                                         flag=false;                                                        break;                                                         }                                                              }                                                              }                                                                  else                                                               {                                                                      for(;high>low;high--)                                              {                                                                      if(arr[high]<temp)                                                 {                                                                      arr[low]=arr[high];                                                low++;                                                             index=high;                                                        flag=true;                                                         break;                                                         }                                                              }                                                              }                                                              }                                                                  arr[high]=temp;                                                    if(high==low)                                                      {                                                                      quickSort(arr,begin,high-1);                                       quickSort(arr,high+1,end);                                     }                                                                                                                                  }                                                                   @Test                                                              public void testquicksort()                                        {                                                                      int[] arr={49,38,65,97,76,13,27,49};                               quickSort(arr, 0, arr.length-1);                                   for (int i = 0; i < arr.length; i++) {                                 System.out.print(arr[i]+"  ");                                                                                                    }                                                              }                                                              

上一篇:快速排序
下一篇:Mysql中DATE_SUB 使用方法结合查询一天内,一周内,一月内的信息实例讲解

相关文章

关键词: 我的快速排序

相关评论