您的位置:首页 > 其它

InsertSort(插入排序)

2015-03-28 16:52 399 查看
#include<iostream>
using namespace std;

void InsertSort( int* array, int n )
{
int j, temp;
for( int i = 1; i < n; i++ )
{
temp = array[i];
j =i - 1;
while( array[j] > temp && j >= 0)
{
array[j+1] = array[j];
j--;
}
array[j+1] = temp;
}
}
void OutPut( int* array, int n )
{
for( int i = 0; i < n; i++ )
{
cout<<array[i]<<"  ";
}
cout<<endl;
}
int main()
{
const int N = 10;
int a
= {13,2,4,16,336,3,8,9,10,11};
OutPut( a, N);
InsertSort( a, N);
OutPut( a, N);
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  InsertSort