#include <iostream>
using namespace std;
int main()
{
int i,j,temp,n,a[30];
cout<<"enter the number of element\n";
cin>>n;//5
cout<<"enter the element\n";
for(i=0;i<n;i++)
{
cin>>a[i];//{12,0,3,1,5}
}
for(i=1;i<n;i++)//i=1
{
temp=a[i];//temp=0
j=i-1;//j=1-1=0,
while(temp<a[j]&&(j>=0))//<12 && j=0(false)
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;//a[0+0]=a[0],12=temp
}
cout<<"sorted list\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
return 0;
}
using namespace std;
int main()
{
int i,j,temp,n,a[30];
cout<<"enter the number of element\n";
cin>>n;//5
cout<<"enter the element\n";
for(i=0;i<n;i++)
{
cin>>a[i];//{12,0,3,1,5}
}
for(i=1;i<n;i++)//i=1
{
temp=a[i];//temp=0
j=i-1;//j=1-1=0,
while(temp<a[j]&&(j>=0))//<12 && j=0(false)
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;//a[0+0]=a[0],12=temp
}
cout<<"sorted list\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
return 0;
}