My selection sort successfully sorts certain numbers yet fails on some. The code seems very logical to me, I even printed step-by-step but somehow it does not work.

```
#include <stdio.h>
#include <string.h>

int number[] = {2, 5, 3, 1};
int length;
void sort(void);
void swap(int *xp, int *yp);

int main(void)
{

    length = sizeof(number)/sizeof(number[0]);
    for (int i = 0; i < length; i++)
    {
        printf("%i ", number[i]);   
    }
    printf("\n");
    sort();
}

void sort(void)
{
    //number

    for (int i = 0; i < length - 1; i++)
    {

        int max = i;
        //printf("max:%i\n",max);
        for (int j = i + 1; j < length; j++)
        {
            //printf("max:%i and j: %i\n",number[max], number[j]);
            if (number[j] > number[max])
            {
                max = j;

                //SWAP WINNER
                swap(&number[max], &number[i]);
            }
        }

        for (int k = 0; k < length; k++)
        {
            printf("%i ", number[k]);
        }
        printf("\n");

    }
    printf("\nnow:\n");
    for (int k = 0; k < length; k++)
    {
        printf("%i ", number[k]);
    }
    printf("\n");
}

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

```

With the result:

```none
2 5 3 1
3 2 5 1
3 5 2 1
3 5 2 1 

now:
3 5 2 1 ~/ $

```

Anyway, another question, why does it have to use pointers? Because it won't work without them. Any suggestions?