Convert array into Zig-Zag fashion

Given an array of distinct elements, rearrange the elements of the array in zig-zag fashion in O(n) time. The converted array should be in form a < b > c < d > e < f.

Example: 
Input: arr[] = {4, 3, 7, 8, 6, 2, 1}
Output: arr[] = {1 ,3 ,2 ,6 ,4 ,8, 7}

Input: arr[] = {1, 4, 3, 2}
Output: arr[] = {1, 4, 2, 3}


Java Code:-
class test{
public static void main(String[] args){
int[] a={4, 3, 7, 8, 6, 2, 1};
int len=a.length;
for(int i=0;i<len;i++){
for(int j=i+1;j<len;j++){
if(a[i]>a[j]){
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(int i=1;i<len-1;i+=2){
int temp=a[i+1];
a[i+1]=a[i];
a[i]=temp;
}
for(int i=0;i<len;i++){
System.out.print(a[i]+"\t");
}
}
}