#include <iostream>
using namespace std;
class insert_sort
{
public:
insert_sort(int *a,int len)
{
this->a = a;
this->num = len;
}
void sort()
{
int place = 0;
for(int i = 1;i<num;i++)
{
place = find_place(a,a[i],i);
insert_element(a,place,a[i],i);
}
}
void display()
{
for(int i = 0;i<num;i++)
cout<<i<<"="<<a[i]<<endl;
}
protected:
int find_place(int *a,int b,int k)
{
int i = 0;
for(i = 0;i<k;i++)
{
if(b<a[i])
{
return i;
}
}
return i;
}
void insert_element(int *a,int ix,int ele,int k)
{
for(int i = k;i>ix&&k>=1;i--)
a[i] = a[i-1];
a[ix] = ele;
}
private:
int num;
int *a;
};
int main(void)
{
int s[12]={1,6,2,3,10,9,7,8,5,34,56,4};
insert_sort sorter(s,12);
sorter.sort();
sorter.display();
return 0;
}
using namespace std;
class insert_sort
{
public:
insert_sort(int *a,int len)
{
this->a = a;
this->num = len;
}
void sort()
{
int place = 0;
for(int i = 1;i<num;i++)
{
place = find_place(a,a[i],i);
insert_element(a,place,a[i],i);
}
}
void display()
{
for(int i = 0;i<num;i++)
cout<<i<<"="<<a[i]<<endl;
}
protected:
int find_place(int *a,int b,int k)
{
int i = 0;
for(i = 0;i<k;i++)
{
if(b<a[i])
{
return i;
}
}
return i;
}
void insert_element(int *a,int ix,int ele,int k)
{
for(int i = k;i>ix&&k>=1;i--)
a[i] = a[i-1];
a[ix] = ele;
}
private:
int num;
int *a;
};
int main(void)
{
int s[12]={1,6,2,3,10,9,7,8,5,34,56,4};
insert_sort sorter(s,12);
sorter.sort();
sorter.display();
return 0;
}