/** * 直接插入排序 * @author TMAC-J * 默认按照从小到大的顺序排列 * 思路:从所有数中选取一个最小的数,用来和第一个数交换,然后再从剩下的数中选取一个最小的数 * 用来和第二个数交换,重复此操作 * */ public class InsertSort { private ... ...
分类:
编程语言 时间:
2017-01-05 21:42:53
阅读次数:
252
static void InsertSort(int[] array) { for (int i = 1; i 0 && array[j - 1] > temp) { array[j] = array[j - 1]; j--; } array[j] = temp; } } ...
分类:
编程语言 时间:
2016-12-28 19:52:06
阅读次数:
161
(╥╯^╰╥) 1 /* 2 请设计直接插入排序算法函数void insertSort(int a[],int n),对a[1]..a[n]进行升序排序。 3 并测试在不同数据规模下的排序效率。 4 */ 5 #include "Arrayio.h" 6 #define N 10000 /*N为数据 ...
分类:
编程语言 时间:
2016-12-23 00:58:30
阅读次数:
383
算法:从第二个元素开始,与前一个元素进行比较,如果小于前一个元素,两者交换位置,一直循环到不再小为止 编译器:VS2013 代码 #include "stdafx.h"#include<stdlib.h> //函数声明void InsertSort(int a[],int n); //插入排序(从小 ...
分类:
编程语言 时间:
2016-12-22 07:00:51
阅读次数:
149
void Insertsort(int a[], int n){ int i, j; int Tmp; for (i = 1; i < n; i++)//from the second element for (j = i - 1; j >= 0 && a[j] > a[j + 1]; j--){ ...
分类:
编程语言 时间:
2016-12-18 01:34:46
阅读次数:
139
一.现象及原因 现象:在一个工程中有2个带有main函数的文件:InsertSort.cpp,ShellSort.cpp InsertSort.cpp 1 #include <stdio.h> 2 3 void InsertSort(int A[],int n) 4 { 5 int i,j; 6 f ...
分类:
编程语言 时间:
2016-10-05 07:14:07
阅读次数:
216
稳定算法: 直接插入排序、折半插入排序、冒泡排序、归并排序 不稳定算法: 希尔排序、快速排序、简单选择排序、堆排序 直接插入排序(从原位置在有序部分逐次比较找到最终位置插入) void InsertSort(ElemType A[], int n) { int i, j; for( i = 2, i ...
分类:
编程语言 时间:
2016-09-11 18:54:29
阅读次数:
216
1、直接插入排序 在一个有序表中插入一个元素形成一个新的表长加1的有序表。 #include <iostream>using namespace std;//直接插入排序void insertSort(int *arr,int length){ for (int i = 1; i <= length ...
分类:
编程语言 时间:
2016-08-18 23:15:07
阅读次数:
164
希尔排序突破了O(n2),它的时间复杂度是O(nlog2n) 分组再排序 public insertSort(int a[],int n){ int i,j,temp; int gap=n;//间隔 do{ gap=gap/3+1; for(int i=gap;i<n-1;i++){ if(a[i] ...
分类:
编程语言 时间:
2016-08-06 16:06:21
阅读次数:
154