InsertSort(插入排序)
来源:互联网 发布:网络填表终结者 下载 编辑:程序博客网 时间:2024/06/06 19:48
插入排序
通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入
//平均时间复杂度O(n^2)//最优时间复杂度O(n)//最坏时间复杂度O(n^2)//空间复杂度O(1)//稳定#include <stdio.h>void InsertSort(int a[], int len){ int i, j; int temp; for (i = 1; i < len; i++) { temp = a[i]; j = i - 1; while (j >= 0 && a[j] > temp) { a[j + 1] = a[j]; j--; } a[j + 1]= temp; }}int main(){ int a[8]; printf("Please input the number:\n"); for(int i=0;i<8;i++) scanf("%d",&a[i]); InsertSort(a, 8); for (int i=0; i<8; i++) { printf("%d\n",a[i]); } return 0;}
阅读全文
0 0
- 插入排序InsertSort
- insertSort - 插入排序
- 插入排序 InsertSort
- 插入排序 InsertSort
- 插入排序(InsertSort)
- 插入排序InsertSort
- 插入排序-InsertSort
- java insertsort 插入排序
- 插入排序-insertsort
- 插入排序(InsertSort)
- 插入排序(InsertSort)
- InsertSort 插入排序算法
- 数据结构-插入排序InsertSort
- InsertSort(插入排序)
- 排序算法-插入排序 insertSort
- 排序算法-InsertSort-插入排序
- 插入排序算法(InsertSort)
- 经典算法-插入排序Insertsort
- jsp SmartUpload上传和下载代码全攻略
- OSGI框架学习
- FFMPEG结构体分析:AVFrame
- 论文级别
- 文章标题
- InsertSort(插入排序)
- TensorFlow教程03:MNIST实验——回归的实现、训练和模型评估
- thread27
- CSS之定位,相对定位,绝对定位,固定定位
- 图像处理之读入写入图像文件
- PHP中MySQL、MySQLi和PDO的用法和区别
- python基础(三)——类的研究
- rsync 守护进程配置(含脚本)
- 算法导论 练习题 17.2-2