Input=1,2,3,4,5
Output=1,3,5,4,2
class sorthigh
{
public static void main(String[]args)
{
int a[]={1,2,3,4,5};
int n=a.length;
int k=0;
if(n%2==0)
k=0;
else
k=1;
while(k<=n-1)
{
for(int i=k;i<n;i+=2)
{
if(i!=n-1)
{
int t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
k++;
}
for(int i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
}
}
Output=1,3,5,4,2
class sorthigh
{
public static void main(String[]args)
{
int a[]={1,2,3,4,5};
int n=a.length;
int k=0;
if(n%2==0)
k=0;
else
k=1;
while(k<=n-1)
{
for(int i=k;i<n;i+=2)
{
if(i!=n-1)
{
int t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
k++;
}
for(int i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
}
}