码迷,mamicode.com
首页 > 其他好文 > 详细

算学学习积累

时间:2019-10-20 15:49:21      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:选择   tostring   one   index   temp   pre   冒泡   clone   import   

排序算法学习积累

import java.util.Arrays;

public class MyTest {

    public static void main(String[] args) throws CloneNotSupportedException {
        int[] x={11,2,33,44,21,5,33,22,33,45,2,50};
/*    //冒泡排序:
            int[] x={11,2,33,44,21,5,33,22,33,45,2,50};
        for (int i = 0; i < x.length-1; i++) {
            for(int j=0;j<x.length-i-1;j++) {
                if (x[j] > x[j + 1]) {
                    int s = x[j];
                    x[j] = x[j + 1];
                    x[j + 1] = s;

                }
            }
        }
        System.out.println("Arrays.toString(x) = " + Arrays.toString(x));*/
     //选择排序
/*        for (int i = 0; i < x.length-1; i++) {
        int j;
        int index=i;
        for(j=i+1;j<x.length;j++){
            if(x[index]>x[j]){
                index=j;
            }
        }
            int s=x[i];
            x[i]=x[index];
            x[index]=s;

    }
        System.out.println(Arrays.toString(x));*/
    //快速排序
        /*        quickSort(x,0,x.length-1);
        System.out.println("Arrays.toString(x) = " + Arrays.toString(x));
}
    public static void quickSort(int[] x,int start,int last){
        if (start<last){
               int s=fastSout(x,start,last);
               quickSort(x,start,s-1);
               quickSort(x,s+1,last);
        }

}
    public static int fastSout(int[] x,int start,int lastright){
        int left = start+1;
        boolean tag = true;
        while (tag){
            while (left<=lastright&&x[left]<=x[start]){
                left+=1;
            }
            while (left<=lastright&&x[lastright]>=x[start]){
                lastright-=1;
            }
            if(left>lastright){
                tag=false;
            }else {
                int temp=x[left];
                x[left]=x[lastright];
                x[lastright]=temp;
            }

        }
        int t=x[start];
        x[start]=x[lastright];
        x[lastright]=t;
        return lastright;*/
   }
}

二分法查找数据

算学学习积累

标签:选择   tostring   one   index   temp   pre   冒泡   clone   import   

原文地址:https://www.cnblogs.com/project-zqc/p/11707747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!