首页 > 编程语言 > 详细

快速排序

时间:2020-07-09 17:20:52      阅读:54      评论:0      收藏:0      [点我收藏+]
package com.example.demo;

/**
 * 快速排序
 */
public class InsertionSort {
    public static void main(String[] args) {
        int[] array = {4, 5, 6, 3, 2, 1};
        InsertionSort insertionSort = new InsertionSort();
        insertionSort.insertionSort(array, array.length);
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

    public void insertionSort(int[] a, int n) {
        for (int i = 1; i < n; i++) {
            int value = a[i];
            for (int j = i - 1; j >= 0; j--) {
                if (a[j] > value) {
                    a[j + 1] = a[j];
                    a[j] = value;
                } else {
//                    break;
                }
            }
        }
    }
}

快速排序

原文:https://www.cnblogs.com/xiaoshahai/p/13274526.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!