Given an array I am required to sort it in such a way that the first element is the smallest value, the second element is the largest, the third element is the second smallest element and so on.
But my code just prints the original array and I am not able to figure out why. Any advice would be appreciated.
#include <stdio.h>
void swap(int m, int n);
int main()
{
int i,j,A[10],n;
printf ("enter the number of array elements\n");
scanf ("%d", &n);
for (i=0;i<n;i++){
scanf ("%d", &A[i]);
}
for (i=0;i<n;i++){
if (i%2 == 0){
for (j=i;j<n;j++){
if (A[j] < A[i]){
swap(A[i],A[j]);
}
}
}
else if (i%2 != 0){
for (j=i;j<n;j++){
if (A[j] > A[i]){
swap (A[i],A[j]);
}
}
}
}
for(i=0;i<n;i++){
printf ("%d\n", A[i]);
}
return 0;
}
void swap( int m, int n)
{
int temp;
temp = m;
m = n;
n = temp;
}