C++插入排序法(Insertion Sort)

2014-11-24 11:34:42 · 作者: · 浏览: 0
// implementation of Insertion Sort (C++)

#include 
  
   

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
   
=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