zoukankan      html  css  js  c++  java
  • 快速排序

    快速排序

     1 package t0107;
     2 
     3 public class PaiXu {
     4 
     5     /**
     6      * 快速排序
     7      */
     8     public void quickSort(String[] strDate, int left, int right) {
     9         String middle,tempDate;
    10         int i,j;
    11         i=left;
    12         j=right;
    13         middle=strDate[(i+j)/2];
    14         do{
    15             while(strDate[i].compareTo(middle)<0 && i<right){
    16                 i++;    //找出左边比中间值大的数
    17             }
    18             while(strDate[j].compareTo(middle)>0 && j>left){
    19                 j--;    //找出右边比中间值大的数
    20             }
    21             if(i<=j){    //将左边大的数和右边小的数进行替换
    22                 tempDate = strDate[i];
    23                 strDate[i]=strDate[j];
    24                 strDate[j]=tempDate;
    25                 i++;
    26                 j--;
    27             }
    28         }while(i<=j);    //当两者交替时停止
    29 
    30         if(i<right){
    31             quickSort(strDate,i,right);
    32         }
    33         if(j>left){
    34             quickSort(strDate,left,j);
    35         }
    36         
    37     }
    38     
    39     public static void main(String[] args) {
    40         String[] strVoid = new String[]{"11","66","22","0","55","22","0","32"};
    41         PaiXu sort = new PaiXu();
    42         sort.quickSort(strVoid,0,strVoid.length-1);
    43         for(int i=0; i<strVoid.length;i++){
    44             System.out.println(strVoid[i]+"");
    45         }
    46     }
    47     
    48 }
  • 相关阅读:
    让IE6 IE7 IE8 IE9 IE10 IE11支持Bootstrap的解决方法
    检测到有潜在危险的 Request.Form 值
    jQuery校验
    C#客户端的异步操作
    泛型(一)
    c#面试题汇总
    多线程(下)
    多线程(上)
    线程篇(二)
    线程篇(一)
  • 原文地址:https://www.cnblogs.com/cfb513142804/p/4209411.html
Copyright © 2011-2022 走看看