selection sort function

i wrote a function that uses a selection sort to sort an array of 25 integers. it calls a swap function i also wrote that swaps the integers. i compiled my code but it is not sorting the array correctly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void selectionSort( int numbers[ ], int list_size )
{
        int unsorted;    //size of unsorted list set to size of list
        int temp;     // temperorary space for integers
        int count;    // index for position in loop
        int pos_max;     // position of maximum value in array

        // loop to start sort
        for( unsorted = list_size; unsorted > 1; unsorted-- )
        {
                pos_max = numbers[0];
                for( count = 1; count < list_size; count++ )
                {
                        if( numbers[count] > pos_max )
                        {
                                swap( numbers[count], pos_max );
                        }
                }
        }
}


swap function
1
2
3
4
5
6
7
8
void swap( int *num1, int *num2 )
{
        int temp;    // temperorary variable

        temp = *num2;
        *num1 = *num2;
        *num2 = temp;
}


any suggestions on what i can do to fix this
Your swap function is so unneeded that is not even being used.

> int pos_max; // position of maximum value in array
but is not used as a position, ¿is it?


Suppose that the biggest number is in `numbers[0]', your code will do nothing.
i see the issue now. cant believe i missed it. but I still do not understand how i can fix it. any ideas
thanks for the help. i fixed the problem
Topic archived. No new replies allowed.