zoukankan      html  css  js  c++  java
  • 并归排序(看别人的看不懂,自己写了一个),排序思想是一样的


    public int[] intArray = {8,5,10,55,88,22,14,36,82,54,10,74,22}; @RequestMapping(value="hello") public int[] getHello(int[] intArray1) { //获取最新排序 intArray1 = intArray; //计算排好序的元素个数,如果次数为数组长度,说明排序成功 int count = 0; int index0 = 0; int indexlast = intArray1.length; for(int i=0; i< indexlast-1; i++){ int start = intArray1[index0]; int next = intArray1[index0+1]; if(start <= next){ count++; index0++; }else{ //前后两元素互换 intArray1[index0] = next; intArray1[index0+1] = start; index0++; } } //把排序结果赋值给参数 ,排序成功则当做结果输出 intArray = intArray1; //如果目前的排好序的元素个数不等于数组长度,继续排序 if(count != indexlast-1){ getHello(intArray); } return intArray; }

    归并排序的基本思想

    将待排序序列R[0...n-1]看成是n个长度为1的有序序列,将相邻的有序表成对归并,得到n/2个长度为2的有序表;将这些有序序列再次归并,得到n/4个长度为4的有序序列;如此反复进行下去,最后得到一个长度为n的有序序列。

    综上可知:

    归并排序其实要做两件事:

    (1)“分解”——将序列每次折半划分

    (2)“合并”——将划分后的序列段两两合并后排序

  • 相关阅读:
    C# 高级编程语言
    unity ForceMode
    UnityError 切换场景灯光变黑问题解决
    Unity Time.timeScale
    Unity 打开网页 Application.OpenURL(字符串);
    Unity www动态加载网上图片
    Unity GameObject.Find 和 transform.Find
    Unity UGUI按钮添加点击事件
    事务
    git和redis
  • 原文地址:https://www.cnblogs.com/kkw105/p/10138487.html
Copyright © 2011-2022 走看看