#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. 软工作业PSP与单元测试训练:java语言判断电子邮箱格式

    任务说明(二选一): 一.实现模块判断传入的身份证号码的正确性: 二.实现模块判断传入的电子邮箱账号的正确性:   实现要求: 一.实现功能模块: 1. 判断邮箱地址是否为空: 2. 判断邮箱地址是否 ...

  2. python 全栈开发笔记 3

    正则表达式 正则表达式(RE)是一种小型的,高度专业化的,它镶嵌在python中,并通过re模块实现,正则表达式编译成一系列的字节码,然后由用c编写的匹配引擎执行. #正则表达式 import re ...

  3. ShellExecute, WinExec与CreateProcess

    0x01  ShellExecute ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件.打开一个目录.打印一个文件等等),并对外部程序有一定的控制.  函数原型: Shel ...

  4. Devexpress的DateEdit控件中DateTime与EditValue异同

    相同: 两者值相同,改变一个值都会引起另一个值做出相应改变. 不同: 1:在界面上对控件的编辑框进行操作时,EditValueChanged事件先响应,DateTimeChanged事件后响应. 2: ...

  5. JS属性修改

    document.getElementById('p1').style.visibility='visible' document.getElementById('p1').style.visibil ...

  6. java导出pdf

    //导出          public void ScoringAnnouncementdownLoad() throws MalformedURLException, IOException, D ...

  7. Real time profiler for Delphi applications

    xalion提供的资源,这么强,还是免费的,快去试用!   ✓  Detailed debug information (internal, TDS, MAP) ✓  Display informat ...

  8. datetime模块

    # 其中days = -2,可以根据需要进行替换,这样就可以得到不同需要的日期了. # # 另外:可以通过strftime方法,指定时间的输出格式. # # 除了以上输入的   %Y-%m-%d    ...

  9. Linux 下SVN报错No repository found in 'svn://210.16.191.230/huandong_project'

    [root@xxxxxx~]# netstat -apn|grep 3690tcp        0      0 0.0.0.0:3690                0.0.0.0:*     ...

  10. Java 程序员必须了解的 7 个性能指标

    来源:王韵菲  本文中,小编搜集了7个最有影响的衡量标注,让你可以不依赖日志文件来了解应用程序.现在,让我们看看这些性能指标,并了解如何查看并收集它们:     1.响应时间和吞吐量 根据应用程序的响 ...