#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,loc,left,right,flag=0,j,b[20],temp;
clrscr();
printf("\nenter the no. of elements to be sorted");
scanf("%d",&n);
printf("\nenter the elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0;
loc=0;
left=loc;
right=n-1;
while(loc<=right)
{
while(loc!=left || loc!=right)
{
if(flag==0)
{
if(a[loc]<a[right])
right--;
else
{
temp=a[loc];
a[loc]=a[right];
a[right]=temp;
loc=right;
flag=1;
}
}
else
{
if(a[loc]>a[left])
left++;
else
{
temp=a[loc];
a[loc]=a[left];
a[left]=temp;
loc=left;
flag=0;
}
}
}
b[i]=loc;
i++;
loc=0;
left=loc;
right=n-1;
for(j=0;j<i;j++)
{
if(loc==b[j])
loc++;
}
}
printf("\nthe sorted elements are=");
for(i=0;i<n;i++)
printf("\t%d",a[i]);
getch();
}