64,649
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
template <class elem>
void swap (elem a[], int i, int j)
{
elem temp = a[i];
a[i] = a[j];
a[j] = temp;
}
template <class elem>
void inssort (elem a[], int size)
{
for( int i = 1; i<size ; i++)
{
for ( int j = i -1; j>=0; j--)
{
if ( a[j] > a[j+1])
{
swap( a, j, j+1);
}
}
}
}
int main()
{
int shuzu [5] = {1,3,5,4,2};
int s = 5;
inssort <int>( shuzu,s);
for ( int temp = 0; temp< 5; temp ++)
{
cout<< shuzu [temp]<<endl;
}
}