#include <bits/stdc++.h>

 using namespace std;
#define MAXSIZE 200000
typedef int KeyType;
typedef struct {
KeyType key;
}RedType;
typedef struct {
RedType r[MAXSIZE + ];
int length;
}SqList;
int Random(int start, int end){
int dis = end - start;
return rand() % dis + start;
}
void InsertSort(SqList &L) {
double start_time, finish_time, cord_time;
start_time = clock();
int i, j;
for (i = ; i <= L.length; ++i) {
if (L.r[i].key < L.r[i-].key) {
L.r[] = L.r[i];
L.r[i] = L.r[i-];
for (j = i-; L.r[].key < L.r[j].key; --j) {
L.r[j+] = L.r[j];
}
L.r[j+] = L.r[];
}
}
finish_time = clock();
cord_time = (double)(finish_time - start_time) ;
printf("InsertSort time=%f ms\n", cord_time);
}
void InPut(SqList &L) {
int i;
srand((unsigned)time(NULL));
cin >> L.length;
for (i = ; i <= L.length; ++i) {
// cin >> L.r[i].key;
L.r[i].key = Random(, );
}
}
void OutPut(SqList &L) {
int i;
for (i = ; i <= L.length; ++i) {
cout << L.r[i].key << " ";
}
}
int main() {
SqList L;
// L.r = new RedType [MAXSIZE+1];
InPut(L);
InsertSort(L);
OutPut(L);
return ;
}

InsertSort的更多相关文章

  1. 三大基础排序算法BubbleSort、SelectSort、InsertSort

    public class Strategy { public static void main(String[] args) { int [] array=new int[]{26,25,15,42, ...

  2. 排序算法FIVE:插入排序InsertSort

    /** *插入排序思路:O(n^2) * 最外层一个循环,从第二个数到最后一个,变量为i * 每个数存储在key变量中 * 变量j,是左边已经排好序的数组的上限 * 判断key与前面每一个数比较 1, ...

  3. Java基础知识强化54:经典排序之插入排序(InsertSort)

    1. 插入排序原理图: 算法步骤: 1)将第一待排序序列第一个元素看做一个有序序列,把第二个元素到最后一个元素当成是未排序序列. 2)从头到尾依次扫描未排序序列,将扫描到的每个元素插入有序序列的适当位 ...

  4. InsertSort 插入排序

    插入排序:将下一个插入已排好的序列中 自己觉得演示的号的一个文章地址 http://sjjg.js.zwu.edu.cn/SFXX/sf1/zjcr.html 下面是java的实现代码: //Inse ...

  5. 《算法导论》习题2.3-6 改进的InsertSort

    InsertSort中有关键的一步是把当前元素A[i]插入到已经排好序的A[1,i-1]的合适的位置上,在原始的InsertSort算法中, 采用的是从后往前一步一步查找的方法,习题2.3-6要求利用 ...

  6. 《算法导论》插入排序----InsertSort

    算法导论,插入排序 public class InsertSort { public static double [] sort(double [] num) { for(int i =1; i< ...

  7. The algorithm learning of sort which include Bubblesort,Insertsort,Quicksort and Mergesort.

    Notice : these algorithms achieved by Java. So,let's going to it. firstly, what is Bubblesort? why w ...

  8. algorithm ch2 insertsort

    刚开始看到insertsort,思路就是使用新来的元素与前述已经排好序的元素比较.然后进行插入或者跳到下一次比较. 实现的代码如下: void InsertSort(int *pArray, int ...

  9. 排序-InsertSort

    数据结构之插入排序 参考----王道论坛2015年数据结构联考复习指南---- 算法稳定性:如果待排序表中有任意两个元素x1,x2相等,且排序前x1在x2的前面,使用某个排序算法之后,若x1仍然在x2 ...

随机推荐

  1. BatchPreparedStatementSetter,用法

    spring批量更新数据 ---- BatchPreparedStatementSetter (2007-04-15 15:41:29) 转载▼ 标签: spring batchpreparedsta ...

  2. 类 Arrays StringBuilder 跟 StringBuffer 的异同 SimpleDateFormat

    类 String 同:起连接字符串类型作用 异: StringBuffer    //线程安全  效率慢 StringBuilder   //线程不安全  效率快 类 Arrays copyOf  ( ...

  3. Springboot 的错误处理功能的实现

    一.页面的形式返回 直接在resources的目录下创建public/error的路径,然后创建5xx.html或者4xx.html文件,如果出错就会自动跳转的相应的页面. 二.cotroller的形 ...

  4. Java语法基础学习DayTwentyOne(网络编程)

    一.IP地址和端口号 1.作用 通过IP地址,唯一的定位互联网上一台主机. 端口号标识正在计算机上运行的进程,不同进程有不同的端口号,被规定为一个16位的整数0~65535,其中0~1023被预先定义 ...

  5. JS中的加减乘除和比较赋值

    隐式类型转换 使用Boolean(), Number(), String()去转换数据类型的方法叫显示类型转换,而与它相对的就是隐式类型转换,隐式类型转换并没有明显的标志,而是JS解释器觉得做这样一个 ...

  6. webservice和dubbo区别

    webservice  不需要搭建注册中心,是一个服务框架,主要内容有soap协议,uuid注册中心,wsdl文件. dubbo   需要搭建注册中心,可以是zookeeper,redis.它是一个分 ...

  7. 【转】Android-Input 触控笔

    https://source.android.com/devices/accessories/stylus 触控笔 Android 6.0 及更高版本支持蓝牙 (BT).蓝牙低功耗 (BTLE) 或 ...

  8. Centos7.4 防火墙配置

    # service firewalld status; #查看防火墙状态 (disabled 表明 已经禁止开启启动 enable 表示开机自启,inactive 表示防火墙关闭状态 activate ...

  9. 【Concurrency-ScheduledExecutorService】

    简介 线程池执行者在ThreadPoolExecutor的基础上给我们提供了延时(delay)执行和周期执行的功能.性能会优于Timer包. 继承结构 参考: ThreadPoolExecutor E ...

  10. C#引用C++的DLL方案(C#调用非托管动态链接库)

    SocketClientInit是C++里面定义的方法,通过EntryPoint = "?SocketClientInit@@YAHHHPAD@Z"指出这个函数的真正入口处,方法是 ...