I used the following approach.

void wiggleSort(int *a,int n)

{

```
int i,j,tmp,k;
if(n<=1)
return;
else
{
qsort(a,n,sizeof(int),cmp); //sort the array
if(n==2)
return;
else
{
for(j=n/2,k=n-1;j<=k;j++,k--) //swap the array from n/2 to n
{
tmp=a[j];
a[j]=a[k];
a[k]=tmp;
}
j=n/2;
for(i=1;i<n;i=i+2) // swap a[i] with a[j] and increament i by i=i+2 and j=j+1
{
if(j<n)
{
tmp=a[i];
a[i]=a[j];
a[j]=tmp;
j=j+1;
}
if(j>=n)
break;
}
}
}}
```