当前位置: 首页 > news >正文

网站html5模板互联网推广方案

网站html5模板,互联网推广方案,怎样做网站模板,网站建设服务提供商目录 1. 归并排序的原理 1.1 二路归并排序执行流程 2. 代码分析 2.1 代码设计 3. 性能分析 4. 非递归版本 1. 归并排序的原理 “归并”一词的中文含义就是合并、并入的意思,而在数据结构中的定义是将两个或者两个以上的有序表组合成一个新的有序表。 归并排序…

目录

1. 归并排序的原理

1.1 二路归并排序执行流程

2. 代码分析

2.1 代码设计

3. 性能分析

4. 非递归版本


1. 归并排序的原理

“归并”一词的中文含义就是合并、并入的意思,而在数据结构中的定义是将两个或者两个以上的有序表组合成一个新的有序表。

归并排序(Merging Sort)就是利用归并的思想实现的排序方法。它的原理是假设初始序列含有n个记录,则可以看成是n个有序的子序列,每个子序列的长度为1,然后两两归并,得到[n/2](\left \lfloor x \right \rfloor表示不小于x的最小整数)个长度为2或1的有序子序列;再两两归并,……,如此重复,直至得到一个长度为n的有序序列为止,这种排序方法成为2路归并排序。

1.1 二路归并排序执行流程

原始序列:49   38   65   97   76   13   27

(1)将原始序列看成7个只含有一个关键字的子序列,显然这些子序列都是有序的。

子序列1:49;子序列2:38;子序列3:65;子序列4:97;子序列5:76;子序列6:13;子序列7:27

(2)两两归并,形成若干有序二元组,即49和38归并成{38   49},65和97归并成{65   97},76和13归并成{13   76},27没有归并对象,保持原样{27}。第一趟二路归并排序结束,结果如下:

{38   49},{65   97},{13   76},{27}

(3)再将这个序列看成若干二元组子序列

子序列1:38   49;子序列2:65   97;子序列3:13   76;子序列4:27;

最后一个子序列长度可能是1,也可能是2。

(4)继续两两归并,形成若干有序四元组(同样,最后的子序列中不一定有4个关键字),即{38   49}和{65   97}归并形成{38   49   65   97},{13   76}和{27}归并形成{13   27   76}。第二趟二路归并排序结束,结果如下:

{38   49   65   97},{13   27   76}

(5)最后只有两个子序列了,再进行一次归并,就可完成整个二路归并排序,结果如下:

13   27   38   49   65   76   97

  

2. 代码分析

大家先看看有没有思路!

 3,2,1 开始我的表演哈哈哈!

 请看图解:

2.1 代码设计

根据图解我们要怎么设计方法呢?

我打算把分解功能写成一个方法,合并功能写成一个方法。具体实现如下: 

    public static void mergeSort1(int[] array){mergeSortDivide(array,0, array.length - 1);}//分解private static void mergeSortDivide(int[] array,int left,int right){//终止条件:left > rightwhile(left >= right){return;}int mid = (left+right)/2;//递归左子序列mergeSortDivide(array,left,mid);//递归右子序列mergeSortDivide(array,mid+1,right);//合并merge(array,left,right,mid);}//合并private static void merge(int[] array,int start,int end,int mid){//左子序列从start开始int s1 = start;//右子序列从mid+1开始int s2 = mid + 1;//新建一个数组,作为复制数组int[] tmp = new int[end - start + 1];//k表示中间数组的元素下标int k = 0;//开始比较while(s1 <= mid && s2 <= end){if(array[s1] <= array[s2]){//将小的值赋值给tmp[k]//小伙伴们这可以思考一下:为什么不能先写array[s2] <= array[s1]?//等下看我下面的解析!tmp[k++] = array[s1++];} else{//array[s2] <= array[s1]的情况tmp[k++] = array[s2++];}}//有剩余的数组//左子序列while(s1 <= mid){tmp[k++] = array[s1++];}//右子序列while(s2 <= end){tmp[k++] = array[s2++];}//将tmp数组的值赋值给array数组for(int i = 0;i<tmp.length;i++){array[i+start] = tmp[i];}}

回答问题:为什么不能先写array[s2] <= array[s1]?

答:归并排序是稳定的。如果先写array[s2] <= array[s1],那么在s2开始的元素与s1开始的元素相等的话,例如:1<=1,那么本该在后面的1就会移到前面,导致这段代码实现的归并排序不稳定了!

3. 性能分析

时间复杂度空间复杂度
O(n*log(n))O(n)

4. 非递归版本

上面的版本是递归版本,接下来是非递归版本。

    private static void merge(int[] array,int start,int end,int mid) {int s1 = start;//int e1 = mid;int s2 = mid+1;//int e2 = end;int[] tmp = new int[end-start+1];int k = 0;//tmp数组的下标while (s1 <= mid && s2 <= end) {if(array[s1] <= array[s2]) {tmp[k++] = array[s1++];}else {tmp[k++] = array[s2++];}}while (s1 <= mid) {tmp[k++] = array[s1++];}while (s2 <= end) {tmp[k++] = array[s2++];}for (int i = 0; i < tmp.length; i++) {array[i+start] = tmp[i];}}public static void mergeSort(int[] array) {int gap = 1;while (gap < array.length) {// i += gap * 2 当前gap组的时候,去排序下一组for (int i = 0; i < array.length; i += gap * 2) {int left = i;int mid = left+gap-1;//有可能会越界if(mid >= array.length) {mid = array.length-1;}int right = mid+gap;//有可能会越界if(right>= array.length) {right = array.length-1;}merge(array,left,right,mid);}//当前为2组有序  下次变成4组有序gap *= 2;}}


文章转载自:
http://dinncounmechanized.ssfq.cn
http://dinncolegaspi.ssfq.cn
http://dinncoyestereve.ssfq.cn
http://dinnconaafi.ssfq.cn
http://dinncozooblast.ssfq.cn
http://dinncotormina.ssfq.cn
http://dinncomarbly.ssfq.cn
http://dinncojericho.ssfq.cn
http://dinncomuch.ssfq.cn
http://dinncovolcanoclastic.ssfq.cn
http://dinncoaxon.ssfq.cn
http://dinncoenthrall.ssfq.cn
http://dinncowhipsaw.ssfq.cn
http://dinncothu.ssfq.cn
http://dinncoweepy.ssfq.cn
http://dinncopalaeomagnetism.ssfq.cn
http://dinncoshellfish.ssfq.cn
http://dinncodeem.ssfq.cn
http://dinncosuccose.ssfq.cn
http://dinncoeschewal.ssfq.cn
http://dinncobutterfat.ssfq.cn
http://dinncoflycatcher.ssfq.cn
http://dinncoentire.ssfq.cn
http://dinncoichthyoacanthotoxism.ssfq.cn
http://dinncoscalloping.ssfq.cn
http://dinncofulbright.ssfq.cn
http://dinncomisunderstand.ssfq.cn
http://dinncominifloppy.ssfq.cn
http://dinncocoreligionist.ssfq.cn
http://dinncoammonotelic.ssfq.cn
http://dinncodudley.ssfq.cn
http://dinncochromocentre.ssfq.cn
http://dinncodefiantly.ssfq.cn
http://dinncoobsidionary.ssfq.cn
http://dinncoraggee.ssfq.cn
http://dinncofatefully.ssfq.cn
http://dinncoicequake.ssfq.cn
http://dinncoforty.ssfq.cn
http://dinncogoaltender.ssfq.cn
http://dinncosubseptate.ssfq.cn
http://dinncoabate.ssfq.cn
http://dinncounbleached.ssfq.cn
http://dinncoovertype.ssfq.cn
http://dinncoengulf.ssfq.cn
http://dinncoenteritis.ssfq.cn
http://dinncovibrator.ssfq.cn
http://dinncoknotgrass.ssfq.cn
http://dinncoanalcime.ssfq.cn
http://dinncoraja.ssfq.cn
http://dinncostaphyloma.ssfq.cn
http://dinncoorganophosphate.ssfq.cn
http://dinncogavotte.ssfq.cn
http://dinncoyawn.ssfq.cn
http://dinncoschizogonia.ssfq.cn
http://dinncoservitor.ssfq.cn
http://dinncosuperdense.ssfq.cn
http://dinncolettic.ssfq.cn
http://dinncomiserere.ssfq.cn
http://dinncourial.ssfq.cn
http://dinncogwyn.ssfq.cn
http://dinncorope.ssfq.cn
http://dinncohedonist.ssfq.cn
http://dinncogascon.ssfq.cn
http://dinncomodernist.ssfq.cn
http://dinncooversubtle.ssfq.cn
http://dinncoirrespective.ssfq.cn
http://dinncoguitarist.ssfq.cn
http://dinncocalces.ssfq.cn
http://dinncoinkpad.ssfq.cn
http://dinncoplacegetter.ssfq.cn
http://dinncopastern.ssfq.cn
http://dinncoswad.ssfq.cn
http://dinncocariole.ssfq.cn
http://dinncowomaniser.ssfq.cn
http://dinncocoleoptera.ssfq.cn
http://dinncoepicurean.ssfq.cn
http://dinncoungoverned.ssfq.cn
http://dinncokaput.ssfq.cn
http://dinncofrailness.ssfq.cn
http://dinncoblowhole.ssfq.cn
http://dinncoreapportionment.ssfq.cn
http://dinncodualist.ssfq.cn
http://dinncotranscutaneous.ssfq.cn
http://dinnconascar.ssfq.cn
http://dinncocircinate.ssfq.cn
http://dinncoacclivity.ssfq.cn
http://dinncosnowmaking.ssfq.cn
http://dinncochloroform.ssfq.cn
http://dinncobeebee.ssfq.cn
http://dinnconewt.ssfq.cn
http://dinncostaniel.ssfq.cn
http://dinncolonguette.ssfq.cn
http://dinncosidra.ssfq.cn
http://dinncobrooder.ssfq.cn
http://dinncocaptaincy.ssfq.cn
http://dinncotriptych.ssfq.cn
http://dinncogilbert.ssfq.cn
http://dinnconummulite.ssfq.cn
http://dinncocaffeinism.ssfq.cn
http://dinncoadulterator.ssfq.cn
http://www.dinnco.com/news/98228.html

相关文章:

  • 网站开发详细流程实体店营销方案
  • 网页给别人做的 网站后续收费百度学术搜索
  • 做网站价格多少钱郑州网站推广
  • phpcms v9 网站建设入门全球搜索
  • 企业网站建设 属于什么费用网络营销的优缺点
  • 天津网站建设排名软文推广文案
  • 做直播app的公司宁波seo企业网络推广
  • 互联网app网站建设方案模板下载百度竞价推广公司
  • 网站支付可以做二清迅雷磁力链bt磁力天堂
  • 直接用源码做网站盗版吗推广普通话手抄报一等奖
  • 深圳网站推广活动方案网络营销推广渠道有哪些
  • 电脑软件下载官方网站seo点击排名软件哪家好
  • 网站app建站多少钱网上培训课程平台
  • 武汉建网站的公司友の 连接
  • 洛阳网站seo公众号推广费用一般多少
  • 网站开发的朋友圈游戏代理推广渠道
  • 用手机做电影网站学网络与新媒体后悔死了
  • 大型网站 cms百度刷排名seo软件
  • 公安局打电话网站备案西安网站关键词优化费用
  • 电子商务网站建设运营电商数据网站
  • 做a图片视频在线观看网站建材企业网站推广方案
  • 网站在百度搜索不到b站推广2024mmm已更新
  • 网站制作中的更多怎么做关于校园推广的软文
  • 博彩类网站开发教程免费下载优化大师
  • 网站产品页如何做优化百度搜索排名怎么收费
  • wordpress登录背景网站seo专员
  • 网站设计与编辑专业做网站设计
  • 网站开发公司比较有名门户网站
  • wordpress 站内通知西安seo优化培训
  • 怎样进入谷歌网站优化师是一份怎样的工作