#include<iostream>
using namespace std;
//假设传入的是一个数组类型的数据
template<typename T>
void Insert_sort(T*array,int size);
int main(){
int a[] ={31,12,3,1,2,9,8,4,2,6,3};
cout<<"原始数据:"<<endl;
for(int i = 0;i<11;i++){
cout<<a[i]<<"\t";
}
cout<<endl;
Insert_sort<int>(a,11);
cout<<"排序后数据:"<<endl;
for(int i = 0;i<11;i++){
cout<<a[i]<<"\t";
}
cout<<endl;
}
template<typename T>
void Insert_sort(T*array,int size){
T temp_numner =static_cast<T>(0);
int j = 0;
for(int i = 1; i<size; i++){
temp_numner = array[i];
for( j =i-1;j>=0;j--){
if(array[j]>temp_numner){
array[j+1] = array[j];
}
else{
array[j+1] = temp_numner;
break;
}
}
if(j < 0 ){
array[0] = temp_numner;
}
}
}