您的位置:首页 > 其它

(算法设计技巧与分析)InsertionSort

2015-03-10 00:34 561 查看


#include<iostream>
#include<time.h>
using namespace std;
void InsertionSort(int a[],int n);
int main()
{
int a[11];
srand((unsigned int(time(NULL))));//导入时间种子加每次运行结样试下伪随机数种子
for (int i=0;i<11;i++)
a[i]=rand();
InsertionSort(a,11);
for(int i=0;i<11;i++)
cout<<a[i]<<" ";
return 0;
}
void InsertionSort(int a[],int n)
{
n--;
if(n>0)
{
InsertionSort(a,n);
int temp=a
;
while(n>0&&a[n-1]>temp)
{a
=a[n-1];n--;}
a
=temp;
/*	for(int i=0;i<n;i++)
cout<<a[i]<<" ";cout<<endl;*/
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: