Sorting an array with alternate smallest and largest values
<p>Given an array, I was asked to sort it in a way so that the smallest values is first the, largest value second, the second smallest value third and so on. However when I input the values I do not get the required output.</p>

<p>Advise is appreciated as I have an exam today.</p>

<pre><code>#include&lt;stdio.h&gt;
int main()

{
    int i,j,k,a[6],temp,min;
    for(i=0;i&lt;6;i++)
    scanf("%d",&amp;a[i]);

    for(j=0;j&lt;6;j++)
    {
        if(j%2==0)
        {
            min=a[j];
            for(k=j;k&lt;6;k++)
            {
                if(a[k++]&lt;min)
                min=a[k++];
            }

            temp=a[j];
            a[j]=min;
            min=temp;
        }
        else
        {
            min=a[j];
            for(k=j;k&lt;6;k++)
            {
                if(a[k++]&gt;min)
                min=a[k++];
            }

            temp=a[j];
            a[j]=min;
            min=temp;
        }
        printf("%d ",a[j]);
    }
}
</code></pre>