#include <iostream>
#include <ctime>
using namespace std;
void RandomArray(int *arr,int arr_len);
void Interpolation(int *arr,int arr_len);
void PrintArray(int *arr,int arr_len);
int main()
{
const static int arr_len = 20;
int arr[arr_len];
RandomArray(arr,arr_len);
PrintArray(arr,arr_len);
Interpolation(arr,arr_len);
PrintArray(arr,arr_len);
return 0;
}
void PrintArray( int *arr,int arr_len )
{
cout<<"打印内容:"<<endl;
for (int i=0;i<arr_len;++i)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
void RandomArray( int *arr,int arr_len )
{
srand(time(NULL));
for (int i=0;i<arr_len;++i)
{
arr[i] = rand()%100;
}
}
void Interpolation( int *arr,int arr_len )
{
for (int i=1;i<arr_len;++i)
{
int tempValue = arr[i];
int j=i;
for (;j>0;--j)
{
if (tempValue>arr[j-1])
{
break;
}
else
{
arr[j] = arr[j-1];
}
}
arr[j] = tempValue;
}
}