Insertion in sorted array..





#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"Enter the values of Sorted array";
int pos,a[5],i,val;
for(i=0;i<5;i++)
{
cin>>a[i];
}
for(i=0;i<5;i++)
{
cout<<a[i];
}
//after insertion
cout<<"Enter the value";
cin>>val;
for(i=0;i<5;i++)
{
 if(a[i]>val)
{
pos=i;
break;
}
}
int j=4;
while (a[j]>a[pos])
{
a[j]=a[j-1];
j--;
}a[pos]=val;
for(int k=0;k<5;k++)
{
cout<<a[k]<<" ";
}
getch();
}
Posted by lol ik

Comments

Popular Posts