直接插入排序(Insertion Sort):
来源:互联网 发布:apache 2.2 漏洞 编辑:程序博客网 时间:2024/06/05 08:33
直接插入排序(Insertion Sort):
基本思想是:每次将一个待排序的记录,按其关键字大小插入到前面已经排好序的子序列中的适当位置,直到全部记录插入完成为止。
源程序如下:
#include <stdio.h>
#define N 10
void insertsort(int a[])
{
int i,j,temp;
for(i=1;i<N;i++)
if(a[i]<a[i-1])
{
temp=a[i]; //将待排序的数放到temp中
for(j=i-1;a[j]>temp;j--) //向前移动数字
a[j+1]=a[j];
a[j+1]=temp;
}
for(i=0;i<N;i++)
printf("%d ",a[i]);
}
int main()
{
int a[N]={10,9,8,7,6,5,4,3,2,1};
insertsort(a);
return 0;
基本思想是:每次将一个待排序的记录,按其关键字大小插入到前面已经排好序的子序列中的适当位置,直到全部记录插入完成为止。
源程序如下:
#include <stdio.h>
#define N 10
void insertsort(int a[])
{
int i,j,temp;
for(i=1;i<N;i++)
if(a[i]<a[i-1])
{
temp=a[i]; //将待排序的数放到temp中
for(j=i-1;a[j]>temp;j--) //向前移动数字
a[j+1]=a[j];
a[j+1]=temp;
}
for(i=0;i<N;i++)
printf("%d ",a[i]);
}
int main()
{
int a[N]={10,9,8,7,6,5,4,3,2,1};
insertsort(a);
return 0;
}
原文地址: http://www.bcoder.cn/?p=415
0 0
- 直接插入排序(Insertion Sort)
- 直接插入排序(Insertion Sort)
- 直接插入排序(Insertion Sort)
- 直接插入排序(Insertion Sort):
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Insertion Sort)
- 1.插入排序—直接插入排序(Straight Insertion Sort)
- 插入排序—直接插入排序(Straight Insertion Sort)
- 插入排序:直接插入排序-Direct insertion sort
- 插入排序(insertion sort)
- insertion sort 插入排序
- 插入排序(Insertion Sort)
- 插入排序 Insertion Sort
- Android SDK eclipse开发工具全套离线下载
- wxpython无标题窗口最大化解决方案
- 【Unity快速实现小功能】加载文本文件之——加载xml文件
- 解决wordpress出现404 not found nginx
- 大白话解析模拟退火算法
- 直接插入排序(Insertion Sort):
- 在Cisco IOS路由器上验证NAT-T的使用
- 【Unity快速实现小功能】加载文本文件之——加载JSON格式文本文件
- 使用Socks5代理下载Android源码
- 多个客户端与一个服务器端通信的问题
- codecolor代码高亮插件下载
- Java本地文件操作-新建、删除、重命名、属性
- 【分享】极客学院视频教程下载
- Linux目录结构