#include<iostream>
using namespace std;
template<typename T>
void insertsort1(T arr[] ,int n)
{
for(int i=1;i<=n-1;i++)
{
for(int j=i;j>0;j--)
{
if(arr[j]<arr[j-1])
swap(arr[j],arr[j-1]);
}
}
}
template<typename T>
void insertsort2(T arr[] ,int n)
{
for(int i=0;i<=(n-1);i++)
{
for(int j=0;j<=(n-1-1)-i;j++)
if(arr[j]>arr[j+1])
swap(arr[j],arr[j+1]);
}
}
int main()
{
int arr[10]={10,9,8,7,6,5,4,3,2,1};
insertsort1(arr,10);
for(int t=0;t<=9;t++)
{
cout<<arr[t]<<" ";
}
cout<<"\n";
insertsort2(arr,10);
for(int t=0;t<=9;t++)
{
cout<<arr[t]<<" ";
}
system("pause");
return 0;
}
#include<iostream>
using namespace std;
template<typename T>
void insertsort(T arr[] ,int n)
{
for(int i=1;i<=n-1;i++)
{
T temp=arr[i];
int j;
for(j=i;j>0;j--)
{
if(arr[j]>temp)
swap(arr[j],arr[j-1]);
}
arr[j]=temp;
}
}
int main()
{
int arr[10]={10,9,8,7,6,5,4,3,2,1};
insertsort(arr,10);
for(int t=0;t<=9;t++)
{
cout<<arr[t]<<" ";
}
cout<<"\n";
float brr[5]={5.5,4.4,3.3,2.2,1.1};
insertsort(brr,5);
for(int t=0;t<=4;t++)
{
cout<<brr[t]<<" ";
}
cout<<"\n";
string crr[4]={"d","c","b","a"};
insertsort(brr,5);
for(int t=0;t<=4;t++)
{
cout<<crr[t]<<" ";
}
system("pause");
return 0;
}