博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
插入排序
阅读量:4622 次
发布时间:2019-06-09

本文共 652 字,大约阅读时间需要 2 分钟。

这是我看算法导论接触的第一个算法

1 #include
2 #include
3 void insert_sort(int a[], int length) 4 { 5 int key; 6 int j; 7 8 for (int i = 1; i < length; i++) 9 {10 key = a[i];11 j = i - 1;12 13 while (a[j] >key && j >= 0)14 {15 a[j + 1] = a[j];16 j--;17 }18 a[j + 1] = key;19 20 }21 for (int i = 0; i < length; i++)22 {23 printf("%d ",a[i]);24 }25 26 }27 int main()28 {29 int matrix[6] = { 31,41,59,26,41,58 };30 insert_sort(matrix, 6);31 return 0;32 33 }

 

 

 

转载于:https://www.cnblogs.com/KIROsola/p/11110526.html

你可能感兴趣的文章
洛谷P1908 逆序对
查看>>
转义符
查看>>
poj 1019
查看>>
asp.net mvc上传文件
查看>>
bitmq集群高可用测试
查看>>
主成分分析(PCA)原理详解
查看>>
短信验证接口网址
查看>>
Geohash距离估算
查看>>
Demon_背包系统(实现装备栏,背包栏,可以切换装备)
查看>>
记录:一次数据库被恶意修改配置文件的问题
查看>>
redis 持久化
查看>>
解决Jupyter notebook[import tensorflow as tf]报错
查看>>
Windows平台下使用ffmpeg和segmenter实现m3u8直播点播
查看>>
python网络画图——networkX
查看>>
ubuntu16.04文件形式安装mongodb
查看>>
SpringBoot------ActiveMQ安装
查看>>
详细了解 int? 类型
查看>>
字符串匹配 ?kmp : hash
查看>>
mongod.service: control process exited, code=exited status=1
查看>>
c# 发送邮件、附件 分类: C# 2014-12-...
查看>>