#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[n];
while(n>0&&a[n-1]>temp)
{a[n]=a[n-1];n--;}
a[n]=temp;
/* for(int i=0;i<n;i++)
cout<<a[i]<<" ";cout<<endl;*/
}
}
(算法设计技巧与分析)InsertionSort
最新推荐文章于 2022-06-20 20:19:14 发布