标签:
理论部分参考:http://blog.csdn.net/txgc0/article/details/7630547
程序参考:http://blog.csdn.net/zz198808/article/details/7537104
// InsertSort.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<iostream> void InsertSort(int a[],int n) { int i,j; int temp; for (i=1;i<n;i++) { temp=a[i];//取出第一个准备插入的数字 for(j=i-1;j>=0 && temp<a[j];j--) { a[j+1]=a[j]; } a[j+1]=temp;//插入数据到序列 } } int _tmain(int argc, _TCHAR* argv[]) { int a[]={2,3,1,5}; InsertSort(a,4); for (int i=0;i<4;i++) { printf("%3d ",a[i]); } system("pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/lwflourish/p/4494025.html