CLRS:Insert sort in in c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#define ARRAY_SIZE 1000
int buf[ARRAY_SIZE];
int main()
{
int i,j,n;
srand((unsigned int)time(0));
memset(buf,0,sizeof(buf[0]));
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)buf[i]=rand()%100;//creat th data storage in buf
for(i=1;i<=n;i++)printf("%d ",buf[i]);//before sort
printf("\nAffter sort:\n");
for(j=2;j<=n;j++)
{
buf[0]=buf[j];
for(i=j-1;i>0&&buf[i]>buf[0];i--)buf[i+1]=buf[i];
buf[i+1]=buf[0];
}
for(i=1;i<=n;i++)printf("%d ",buf[i]);//after sort
printf("\n");
}
}
CLRS:Insert sort in in c的更多相关文章
- 计数排序(Count Sort )与插入排序(Insert Sort)
计数排序法:计数数组适用于当前数组密集的情况.例如(2,3,5,4,2,3,3,2,5,4) 方法:先找出最大值最小值,之后统计每个数出现的次数,根据次数从小到大往数组里添加 计数排序法是一种不需要比 ...
- c++算法联系,冒泡排序,bubble sort,插入排序,insert sort,
#include <iostream.h> #define MAX 100 void dispaly(int a[],int n) { for(int i=0;i<n;i+ ...
- Insert Sort Singly List
对单链表插入排序,给出个单链表的head节点:返回排完序的head节点: 首先数据结构中习惯了以数组为参数排序,瞬间想到是遍历单链表存入arraylist中,再进行insert sort,(O(n** ...
- insert sort
插入排序将数据分为前面有序部分和后面无序部分,取无序部分的第一个元素插入到有序序列中. 注意与选择排序的区别. // insert sortvoid insertionSort(int arr[], ...
- leetcode:Insert Sort List
问题描写叙述 对一个单链表进行插入排序,head指向第一个结点. 代码 /** * Definition for singly-linked list. * struct ListNode { * i ...
- 插入排序(1)——直接插入排序(insert sort)
假设有一组无序序列 R0, R1, ... , RN-1. (1) 我们先将这个序列中下标为 0 的元素视为元素个数为 1 的有序序列. (2) 然后,我们要依次把 R1, R2, ... , RN- ...
- Java经典算法之插入排序(Insert Sort)
插入排序在局部有序的情况下比冒泡排序快一倍,比选择排序快一点. 那什么是插入排序,就是将局部有序的数据向右移动,将未排序的数据插到他的前面 下面我们来解析代码: 这里外层循环out变量从1开始向右移动 ...
- Sort Methods
heyheyhey ~~ It has been a long time since i come here again...whatever today i will summerize some ...
- CLRS:sorting in linear time O(n)
//intput array A,output array result. count array count . //all the elements is in te range of 0~k ...
随机推荐
- iphone Dev 开发实例9:Create Grid Layout Using UICollectionView in iOS 6
In this tutorial, we will build a simple app to display a collection of recipe photos in grid layout ...
- AP_AP系列 - 付款管理分析(案例)
2014-07-08 Created By BaoXinjian 一.摘要 1. 付款 2. 发票付款概述 3. 使用发票工作台付款 4. 使用付款管理器付款 5. 银行账户模型 二.流程分析 1. ...
- POJ 2195 Going Home 最小费用流 裸题
给出一个n*m的图,其中m是人,H是房子,.是空地,满足人的个数等于房子数. 现在让每个人都选择一个房子住,每个人只能住一间,每一间只能住一个人. 每个人可以向4个方向移动,每移动一步需要1$,问所有 ...
- php socket 学习
socket超时设置 ini_set("default_socket_timeout", -1); stream_set_timeout $fp = fsockopen(" ...
- git(4)如何在windows上安装git
windows版本git(1.9.2)下载:点击下载 下完之后点击双击安装: 我安装的是默认的目录:一路next,最后就安装完成了,中间步骤中也有unix下安装的选项: 我的安装目录是在:C:\Pro ...
- DB2 SQL性能调优秘笈
SQL优化技巧 1.去除在谓词列上编写的任何标量函数 2.去除在谓词列上编写的任何数学运算 3.SQL语句的Select部分只写必要的列 4.尽可能不用Distinct 5.尽量将In子查询重写为Ex ...
- 转载__UI之Frgment
http://www.cnblogs.com/plokmju/p/3239265.html 前言 开门见山开篇名义,本篇博客将讲解一下Android中Fragment的内容,必要的地方会提供相应的演示 ...
- firebug下载时出现there was an error loading firebug
打开Firefox -> Preferences -> Advance ->Certificates 将Query OSCP....前面的checkbox取消
- jquery ready 延迟
$.holdReady(true);//延迟 $.holdReady(false);//解延迟 用于下载文件的时候,异步操作 $.holdReady(true); $.getScript(" ...
- 记录更新rbenv 和 ruby-build安装2.3的ruby注意细节
安装就不说了,官网有,但是今天发布了ruby2.3,所以更新一下 进入.rbenv目录,执行git pull 更新,但是更新了rbenv,执行rbenv install -l 并没有最新的2.3.0 ...