今天就跟大家聊聊有关Java中的排序方法有哪些,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。直接插入排序<code class="language-java hljs
今天就跟大家聊聊有关Java中的排序方法有哪些,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
直接插入排序
<code class="language-java hljs ">import java.util.HashMap; public class InsertSort { private static int contrastCount = 0;//对比次数 private static int swapCount = 0;//交换次数 public static void main(String[] args) { System.out.println("直接插入排序:\n 假设前面的序列都已经排序好了,把后面未排序的数往已排好序的序列内插入,时间复杂度O(n^2),空间复杂度O(1),稳定排序"); HashMap<integer,integer> hashMap = new HashMap<integer,integer>(); init(hashMap);//初始化 System.out.println("初始序列为:"); print(hashMap, 0);//打印 insert(hashMap);//排序 } private static void init(HashMap<integer, integer=""> hashMap) { hashMap.put(0, null);//第一位置空 hashMap.put(1, 0); hashMap.put(2, 5); hashMap.put(3, 11); hashMap.put(4, 12); hashMap.put(5, 13); hashMap.put(6, 4); hashMap.put(7, 1); hashMap.put(8, 5); hashMap.put(9, 8); hashMap.put(10, 6); hashMap.put(11, 4); hashMap.put(12, 8); } private static void insert(HashMap<integer, integer=""> hashMap){ System.out.println("开始插入排序:"); int i,j; //排序开始时间 long start = System.currentTimeMillis(); for(i=2; i<hashmap.size(); author="" code="" contrastcount="0;//对比次数" count="1;//只为统计执行次数" d="1,时间复杂度o(n^1.3),空间复杂度o(1),不稳定排序");" end="System.currentTimeMillis();" h3="" hashmap="" hhf="" hillsort="" i="1;" id="希尔排序" import="" int="" integer="" j="" long="" n="" param="" pre="" private="" public="" start="System.currentTimeMillis();" static="" swapcount="0;//交换次数" void="" x="1;x<=d;x++){//一共有d组"></hashmap.size();></integer,></integer,></integer,integer></integer,integer></code>
--结束END--
本文标题: Java中的排序方法有哪些
本文链接: https://www.lsjlt.com/news/226842.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0