package com.algorithm; /** * Created by nanzhou on 2017/7/24. */ public class InsertSort { /** * 插入排序 * * @param args */ public static void main(String[] args) { int[] arr = new int[]{122, 23, 324, 425, 456, 657, 717, 859, 690}; for (int i = 0; i < arr.length; i++) { for (int j = i; j > 0; j--) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; } else { break; } } } for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + ","); } } }
插入排序
最新推荐文章于 2025-03-31 10:53:38 发布
本文介绍了一种简单的排序算法——插入排序,并通过Java代码实现了该算法。示例代码中使用了一个整数数组作为输入,并展示了如何逐步将数组按升序排列。
2573

被折叠的 条评论
为什么被折叠?



