<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    常見(jiàn)排序法:

    public class Sort{
    ???public static int count=0;

    ???public boolean LT(int num1,int num2){
    ??????return num1<num2;
    ???}
    ???public void output(int[] array){
    ??????System.out.print("第"+count+"次排序:");
    ??????for(int i=0;i<array.length;i++)
    ??????System.out.print(array[i]+"??? ");
    ??????System.out.println();
    ???}

    ???//冒泡排序法
    ???public void BubbleSort(int[] array){
    ??????boolean swap=true;
    ??????int index=0;

    ??????int i=0;
    ??????while(i<array.length-1){
    ?????????int temp=array[i];
    ?????????for(int j=i;j<array.length;j++){
    ????????????if(!LT(array[i],array[j])){
    ????????????int temp2=array[i];
    ????????????array[i]=array[j];
    ????????????array[j]=temp2;
    ????????????swap=true;
    ????????????index=j;
    ????????????}else{
    ????????????swap=false;
    ????????????}
    ?????????}
    ?????????i++;
    ?????????if(swap){
    ?????????array[i]=array[index];
    ?????????array[index]=temp;
    ?????????i++;
    ?????????}
    ???output(array);
    ???}
    ???}


    //直接插入排序法
    public void InsertSort(int[] array){
    ???for(int i=1;i<array.length;++i){
    ??????if (LT(array[i],array[i-1])){
    ?????????int temp=array[i];
    ?????????array[i]=array[i-1];
    ?????????array[i-1]=temp;
    ?????????for(int j=i-1;j>0;--j){
    ????????????if(LT(array[j],array[j-1])){
    ???????????????array[j]=array[j-1];
    ???????????????array[j-1]=temp;
    ????????????}else{
    ??????????????????break;
    ????????????????????}
    ?????????}
    ???output(array);
    ???}
    }
    }


    //快速排序法
    private int Partition(int array[],int low,int high){
    ???int temp=array[low];
    ???int pivotkey=array[low];

    ???while(low<high){
    ??????while(low<high&&array[high]>pivotkey) --high;
    ??????array[low]=array[high];
    ??????while(low<high&&array[low]<=pivotkey) ++low;
    ??????array[high]=array[low];
    ???}
    ???array[low]=temp;
    ???output(array);
    ???return low;
    }


    public void QSort(int array[],int low,int high){
    ???if(low<high){
    ??????int pivotloc=Partition(array,low,high);
    ??????QSort(array,low,pivotloc-1);
    ??????QSort(array,pivotloc+1,high);
    ???}
    }


    void QuickSort(int array[]){
    ???QSort(array,0,array.length-1);
    }

    public static void main(String args[]){
    ???int array[]={49,38,65,97,76,13,27,49};
    ???Sort sort=new Sort();

    ???System.out.println("===================================");
    ???sort.output(array);
    ???System.out.println("優(yōu)化冒泡排序法");
    ???sort.BubbleSort(array);

    ???System.out.println();
    ???System.out.println("===================================");
    ???array=new int[]{49,38,65,97,76,13,27,49};
    ???sort.output(array);
    ???System.out.println("直接插入排序法");
    ???sort.InsertSort(array);

    ???System.out.println();
    ???System.out.println("===================================");
    ???array=new int[]{49,38,65,97,76,13,27,49};
    ???sort.output(array);
    ???System.out.println("快速排序法");
    ???sort.QuickSort(array);
    }
    }

    ?


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 成视频年人黄网站免费视频| 又粗又硬又黄又爽的免费视频| 久久精品国产免费观看三人同眠| 永久免费AV无码国产网站| 精品亚洲A∨无码一区二区三区| 亚洲va乱码一区二区三区| 国产裸体美女永久免费无遮挡| 四虎永久在线精品免费观看视频| 久久久青草青青国产亚洲免观 | 全免费A级毛片免费看网站| 亚洲午夜久久久久久久久电影网| 亚洲视频无码高清在线| 久久精品一区二区免费看| 亚洲国产一区视频| 亚洲午夜精品久久久久久app| 一级毛片免费观看不卡视频| 亚洲综合国产精品第一页| 亚洲精品无码永久在线观看男男| 99久9在线|免费| 亚洲无线码在线一区观看| 国色精品va在线观看免费视频| 男人的天堂亚洲一区二区三区 | 亚洲av中文无码乱人伦在线播放 | 久久久免费观成人影院| 久久丫精品国产亚洲av不卡| 国拍在线精品视频免费观看| 欧美激情综合亚洲一二区| 免费A级毛片无码免费视| 亚洲永久中文字幕在线| 一级毛片免费播放| 亚洲色大成网站www| 久久精品国产亚洲7777| 24小时日本电影免费看| 亚洲色图在线观看| 免费在线看黄的网站| 亚洲大尺度无码无码专区| 99精品视频在线观看免费| 国产亚洲精品免费视频播放| 99久9在线|免费| 一级成人a做片免费| 亚洲天堂免费在线视频|