C++插入排序法(Insertion Sort)
来源:互联网 发布:ubuntu 16.04应用商店 编辑:程序博客网 时间:2024/04/30 03:02
// implementation of Insertion Sort (C++)#include <iostream>using namespace std;void SwapTwo(int &a, int &b){ int temp = a; a = b; b = temp;}void InsertSort(int arr[], int size){ for (int i=1; i<size; i++) { int inserter = arr[i]; int index = i-1; while (index>=0 && inserter < arr[index]) { arr[index+1] = arr[index]; index--; } arr[index+1] = inserter; }}int main(){ int nums[] = {5,3,7,2,1,9,14,8,7,4,30,18,1,23,27}; int size = sizeof(nums)/sizeof(int); InsertSort (nums, size); for (int i=0; i<size; i++) { cout << nums[i] << " "; } cout << endl; return 0;}
0 0
- [C++] 插入排序法 (Insertion sort)
- (C#)插入排序 Insertion Sort
- 插入排序(insertion sort)
- insertion sort 插入排序
- 插入排序(Insertion Sort)
- 插入排序 Insertion Sort
- 插入排序Insertion sort
- 插入排序 (Insertion Sort)
- 插入排序Insertion sort
- 插入排序 Insertion Sort
- 插入排序 insertion sort
- 插入排序 insertion sort
- 插入排序Insertion sort
- 插入排序 Insertion sort
- 插入排序 Insertion Sort
- 插入排序-----Insertion Sort
- INSERTION-SORT插入排序
- 插入排序Insertion Sort
- Android 通过solid来定义不同边框的颜色,可以只定义一个边框的颜色
- SQL 数据库的删除
- NoSQL数据库Redis(REmote DIctionary Server)使用介绍和特性
- 最大流练习:Parking,二分匹配
- 记录Linux的点点滴滴
- C++插入排序法(Insertion Sort)
- 同步/异步与阻塞/非阻塞的区别
- UIGestureRecognizer
- 从杂乱到有序并不简单--排序算法之一冒泡法
- 微软笔试题 统计英文电子书中出现次数最多的k个单词
- 最短路问题总结
- 初学ucore操统笔记(1)
- P1190 繁忙的都市(Kruskal)
- 黑马程序员_IO流(三)