ITPub博客

首页 > IT职业 > IT图书 > 插入排序算法优化(Java)

插入排序算法优化(Java)

IT图书 作者:jinxiaoliang 时间:2021-09-09 08:59:49 0 删除 编辑
/**
 * Created by yuyong on 2017/3/2.
 */
public class InsertionSort {

    public void insertionSort(int arr[], int n) {

        for (int i = 1; i  0 && arr[j - 1] > temp; j--) {
                arr[j] = arr[j - 1];
            }
            arr[j] = temp;
        }

    }

    public static void main(String[] args) {

        int[] a = {10, 8, 1, 5, 2, 9, 7, 6, 4, 3};

        InsertionSort is = new InsertionSort();
        is.insertionSort(a, 10);
        for (int i = 0; i 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3996/viewspace-2807547/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-17

  • 博文量
    73
  • 访问量
    534