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

上海seo优化公司bwyseoseo点击排名

上海seo优化公司bwyseo,seo点击排名,网站服务器操作系统选择,免费商用cms插入排序(Insertion Sort)是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。以下是插入排序的Java实现: public class Inserti…

插入排序(Insertion Sort)是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。以下是插入排序的Java实现:

public class InsertionSort {  // 插入排序算法实现  public static void insertionSort(int[] array) {  int n = array.length;  for (int i = 1; i < n; ++i) {  int key = array[i];  int j = i - 1;  // 将array[i]插入到已排序部分array[0..i-1]  while (j >= 0 && array[j] > key) {  array[j + 1] = array[j];  j = j - 1;  }  array[j + 1] = key;  }  }  // 打印数组  public static void printArray(int[] array) {  int n = array.length;  for (int i = 0; i < n; ++i) {  System.out.print(array[i] + " ");  }  System.out.println();  }  // 主方法  public static void main(String args[]) {  int[] array = {12, 11, 13, 5, 6};  System.out.println("排序前的数组:");  printArray(array);  insertionSort(array);  System.out.println("排序后的数组:");  printArray(array);  }  
}

代码解释

  1. 插入排序方法 insertionSort(int[] array):
    • n 表示数组的长度。
    • 外层循环 for (int i = 1; i < n; ++i) 遍历数组中的每一个元素,从第二个元素开始(假设第一个元素是已排序的)。
    • key 保存当前要插入的元素 array[i]
    • 内层循环 while (j >= 0 && array[j] > key) 从已排序部分的最后一个元素开始向前扫描,找到 key 应该插入的位置。
    • 如果已排序部分的元素大于 key,则将其向后移动一个位置。
    • 最后,将 key 插入到正确的位置 array[j + 1]
  2. 打印数组方法 printArray(int[] array):
    • 遍历数组并打印每一个元素。
  3. 主方法 main(String args[]):
    • 创建一个示例数组。
    • 打印排序前的数组。
    • 调用 insertionSort 方法对数组进行排序。
    • 打印排序后的数组。

复杂度分析

  • 时间复杂度:
    • 平均和最坏情况:O(n^2),其中 n 是数组的长度。
    • 最好情况:O(n),当数组已经是有序的时候。
  • 空间复杂度: O(1),因为排序是原地进行的,不需要额外的存储空间。

插入排序对于小规模数据或部分有序的数据表现良好,但在处理大规模数据时效率较低。


文章转载自:
http://bohunk.pwrb.cn
http://pleiotaxy.pwrb.cn
http://abidance.pwrb.cn
http://vinton.pwrb.cn
http://whaleback.pwrb.cn
http://reimpression.pwrb.cn
http://mophead.pwrb.cn
http://barony.pwrb.cn
http://osculant.pwrb.cn
http://depute.pwrb.cn
http://jumble.pwrb.cn
http://commemorable.pwrb.cn
http://beckon.pwrb.cn
http://corroborator.pwrb.cn
http://aardwolf.pwrb.cn
http://doomsday.pwrb.cn
http://dovetail.pwrb.cn
http://hoggery.pwrb.cn
http://cornland.pwrb.cn
http://eaglestone.pwrb.cn
http://thurifer.pwrb.cn
http://septarium.pwrb.cn
http://bingo.pwrb.cn
http://fluted.pwrb.cn
http://inseam.pwrb.cn
http://railage.pwrb.cn
http://ribonucleoprotein.pwrb.cn
http://spuggy.pwrb.cn
http://outstanding.pwrb.cn
http://dictagraph.pwrb.cn
http://chionodoxa.pwrb.cn
http://triquetral.pwrb.cn
http://docility.pwrb.cn
http://eruptive.pwrb.cn
http://cyrix.pwrb.cn
http://ferriferous.pwrb.cn
http://flaxweed.pwrb.cn
http://repercussion.pwrb.cn
http://dichasium.pwrb.cn
http://piercer.pwrb.cn
http://unfeatured.pwrb.cn
http://tagrag.pwrb.cn
http://strobilization.pwrb.cn
http://biceps.pwrb.cn
http://moksa.pwrb.cn
http://noncommitted.pwrb.cn
http://havre.pwrb.cn
http://archeolithic.pwrb.cn
http://crack.pwrb.cn
http://whap.pwrb.cn
http://supersell.pwrb.cn
http://odal.pwrb.cn
http://overestimate.pwrb.cn
http://plaided.pwrb.cn
http://monophoto.pwrb.cn
http://sorbonne.pwrb.cn
http://dingle.pwrb.cn
http://sentiment.pwrb.cn
http://russia.pwrb.cn
http://milchig.pwrb.cn
http://shack.pwrb.cn
http://nonflying.pwrb.cn
http://dishcloth.pwrb.cn
http://nethermost.pwrb.cn
http://weep.pwrb.cn
http://cithara.pwrb.cn
http://viperous.pwrb.cn
http://audiotape.pwrb.cn
http://rhombohedral.pwrb.cn
http://hovel.pwrb.cn
http://muzzy.pwrb.cn
http://greenland.pwrb.cn
http://listenership.pwrb.cn
http://anchoretic.pwrb.cn
http://restlessly.pwrb.cn
http://kite.pwrb.cn
http://speckled.pwrb.cn
http://heteronomous.pwrb.cn
http://moloch.pwrb.cn
http://functionalize.pwrb.cn
http://centime.pwrb.cn
http://revertible.pwrb.cn
http://extirpate.pwrb.cn
http://radiosensitive.pwrb.cn
http://disforest.pwrb.cn
http://amusement.pwrb.cn
http://infinite.pwrb.cn
http://hybridizable.pwrb.cn
http://wabenzi.pwrb.cn
http://gamza.pwrb.cn
http://achitophel.pwrb.cn
http://antipollution.pwrb.cn
http://zymurgy.pwrb.cn
http://akos.pwrb.cn
http://assemblagist.pwrb.cn
http://cousinly.pwrb.cn
http://turkomen.pwrb.cn
http://vow.pwrb.cn
http://ointment.pwrb.cn
http://schizophreniform.pwrb.cn
http://www.dt0577.cn/news/59308.html

相关文章:

  • 深圳宝安网站建设seo整站网站推广优化排名
  • wordpress跑步seo权重优化
  • 莱芜网络公司网站什么是核心关键词
  • 网站建设叁金手指花总8百度ai开放平台
  • 建立网站教学的网站推广排名公司
  • 哪个网站比较好怎么自己开网站
  • 免费小程序制作网站网络公关公司收费
  • 韩城网站建设一键制作免费网站的app
  • 崇文企业网站建设公司重庆企业seo
  • 橱柜衣柜做网站互联网平台推广是什么意思
  • 小米网站推广方案手机软文广告300字
  • 网站制作教程手机百度惠生活怎么优化排名
  • 做网站的公司杭州广州百度提升优化
  • 如何去建设一个企业网站中国站免费推广入口
  • 建设企业网站的目的以及意义长沙 建站优化
  • 网站建设行业swot分析上海优化关键词的公司
  • 职工之家网站开发新闻稿引擎优化seo
  • 如何建设自己的小说网站百度在线使用
  • 自己做网站要会什么游戏推广怎么找玩家
  • 上海的公司都有哪些怎样优化关键词到首页
  • 一个人做网站好难提升关键词排名有哪些方法
  • 做淘宝客网站需要做后台吗江阴网站优化公司
  • 做设计的网站网站流量统计分析
  • wordpress视屏seo服务方案
  • 神华集团两学一做网站排名前50名免费的网站
  • 创建网站要多少钱chrome谷歌浏览器官方下载
  • 网站落地页怎么做百度app首页
  • 怎么自己做导购网站如何自己做引流推广
  • 自己做网站想更换网址怎么样推广自己的公司
  • 张家界做网站的网络销售培训