插入排序是最常用的排序之一。

在输入规模较小的时候,插入排序的性能较好。

最好情况下插入排序的时间复杂度是O(n),平均情况则为O(n2)。

插入排序是稳定的排序算法之一。

基本思路为从第二个元素开始,依次插入前面已经排好序的序列,利用循环不变式很容易理解。

代码如下:(仅供参考)

 void InsertionSort(int * const begin, int * const end) {
int i, j;
int key;
for (i = ; i < end - begin; ++i) {
key = *(begin + i);
for (j = i - ; j >= && (*(begin + j) > key); --j) {
*(begin + j + ) = *(begin + j);
}
*(begin + j + ) = key;
}
}

注:指针需要支持随机访问

最新文章

  1. CozyRSS开发记录18-番外之Atom1.0的支持
  2. easyui DataGrid 工具类之 util js
  3. [知识点]Trie树和AC自动机
  4. linux注销开关机
  5. win8上安装 Pillow
  6. 设计模式之前奏(UML类图)
  7. Ehcache 的简单实用 及配置
  8. 移动端车牌识别、行驶证识别OCR为共享汽车APP增添技术色彩
  9. Docker 单主机网络
  10. PCA,到底在做什么
  11. heartbeat 非联网安装(通过配置本地yum文件库安装heartbeat)
  12. Modbus库开发笔记之二:Modbus消息帧的生成
  13. git push以后GitHub上文件夹灰色 不可点击
  14. ubuntu-14.04.2-desktop-i386.iso:ubuntu-14.04.2-desktop-i386:安装Oracle11gR2
  15. Codeforces 691C. Exponential notation 模拟题
  16. jquery-插入兄弟元素
  17. Hibernate 干货
  18. ActionContextCleanUp
  19. Hibernate框架基础
  20. hdu 4074 Darts

热门文章

  1. Linux每日一练20200219
  2. 安装kubernetes遇见coredns坑
  3. spring+springMVC+mybatis , 项目启动遇坑
  4. Linux - 安装 dotnet core 环境
  5. 吴裕雄--天生自然Django框架开发笔记:Django Admin 管理工具
  6. [XSS防御]HttpOnly之四两拨千斤
  7. CountDownLatch和CyclicBarrier和Semaphore最通俗形象解释
  8. CodeForces - 748D Santa Claus and a Palindrome (贪心+构造)
  9. Aras Innovator Method集成Visual Studio
  10. macOS下的播放器