// insert_soort_rec.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
//基于递归插入排序算法
void RecursionInsert(int A[],int n)
{
int k;
int a;
n = n-1;
if(n>0)
{
RecursionInsert(A,n);
a = A[n];
k = n-1;
while((k>=0) && (A[k]>a))
{
A[k+1] = A[k];
k = k-1;
}
A[k+1] = a;
}
}
int main(int argc, char* argv[])
{
int Array[20];
int ArraySize;
cout<<"请输入数组的个数:"<<endl;
cin>>ArraySize;
cout<<"请输入数组元素,元素之间用空格隔开(最多不得超过20个元素)"<<endl;
for(int i = 0;i<ArraySize;i++)
cin>>Array[i];
RecursionInsert(Array,ArraySize);
for(int j=0;j<ArraySize;j++)
cout<<Array[j]<<'/t';
return 0;
}
运算结果: