|
CPP Program To Implement Insertion Sort : |
|
#include
#include
class InsertionSort
{
public:
void insertion_sort(int [],int);
};
void InsertionSort :: insertion_sort(int x[],int length)
{
int key,i;
for(int j=1;jkey && i>=0)
{
x[i+1]=x[i];
i--;
}
x[i+1]=key;
}
}
void main()
{
int A[100],x,n;
InsertionSort q;
clrscr();
cout<>n;
cout<<"\n\nEnter the elements\n\n";
for(x=0;x>A[x];
cout<
SAMPLE INPUT AND OUTPUT:
ENTER THE LIMIT : 5
ENTER THE ELEMENTS ONE BY ONE
5
4
3
2
1
SORTED LIST
1
2
3
4
5
|
|
⇓ Student Projects ⇓
⇑ Student Projects ⇑ |