Algorithm--Insertion Sort
来源:互联网 发布:ubuntu tftp 不能启动 编辑:程序博客网 时间:2024/05/18 01:16
插入排序
package practice1;public class InserSort {/** * Insertion Sort: 每次把一个项按照关键字大小插入到前面已经排好序的子文件中的适当位置,直到全部插入完成 * 时间复杂度:T(n) = O(n^2) * 在输入规模较小的情况下,使用插入排序 * @param array */public static int[] insertSort(int[] array){int j, current;for(int i=1; i<array.length; i++){current = array[i];j = i-1;while (j >= 0 && current < array[j]) {array[j+1] = array[j];j--;}array[j+1] = current;}return array;}/** * print the array * @param arr */public static void printArray(int[] arr){for(int i = 0;i<arr.length;i++){System.out.println(i+"---"+arr[i]);}}/** * produce random array * @param num * @return */private static int[] produceIntList(int num) {int list[] = new int[num];for(int i=0; i<num; i++){int temp = (int) (Math.random() * 10000);list[i] = temp;}return list;}public static void main(String[] args) {int[] list = produceIntList(100000);long time1 = System.currentTimeMillis();list = insertSort(list);long time2 = System.currentTimeMillis();System.out.println("the time used is : "+(time2 - time1));}}
0 0
- Insertion sort algorithm
- Algorithm--Insertion Sort
- Sorting Algorithm-Straight Insertion Sort
- Sort Algorithm Part-2 Insertion Sort
- Insertion Algorithm
- One Algorithm A Day --- INSERTION-SORT--算法入门
- Introduction to Algorithm - Summary of Chapter 2(1) - Insertion sort
- Insertion Sort
- Insertion Sort
- insertion sort
- insertion sort
- Insertion Sort
- insertion sort
- insertion sort
- insertion sort
- insertion sort
- Insertion Sort
- Insertion Sort
- IOS HTTP 之同步请求、异步请求、GET请求、POST请求
- Unity3D研究院之Unity中连接本地或局域网MySQL数据库(五十九)
- 判断字符串A中是否包含字符串B
- SqlHelper类
- android从应用到驱动之—camera(1)---程序调用流程
- Algorithm--Insertion Sort
- 希尔排序
- Python os.walk()和os.path.walk()
- 一、Yii框架学习之单选框
- obj-c内存管理的规则
- webkit内核(chrome、safari) 、FF、IE 、opera 下的linear-gradient 写法
- struts返回json数据解析
- linux 增加sudo权限
- 输出gdb调试信息到文件中