CALCULATE INSERTION SORT

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

// PRIGRAM TO CALCULATE INSERTION SORT

#include<iostream.h>
#include<conio.h>
void main()
{
const int n=5;int a[n];
clrscr();
cout<<“\nEnter the array element=”;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<—————————————-\n”;
cout<<“\n original array is=”;
for(i=1;1<=n;i++)
{
cout<<a[i]<<” “;
}
int ptr,temp;
a[0]=-0;
for(int k=2;k<=n;k++)
{
temp=a[k];
ptr=k-1;
while(temp<a[ptr])
{
a[ptr+1]=a[ptr];
ptr–;
}
a[ptr+1]=temp;
}
cout<<‘\n————————————————-“;
cout<<“\n
for(i=1;i<=1;i++)
{
cout<<a[i]<<” “;
}
getch();
}

============================output========================

Enter the array elements=3 6 8 2 1

——————————————–

orginal array is=3 6 8 2 1
——————————————-
sorted array is=1 2 3 6 8

Leave a Reply

Your email address will not be published. Required fields are marked *