You've also named your function that returns the minimum value
findMax.
7 8
|
for (int i=0; i < 24; i++)
{
|
I think you meant
i < array
here rather than
i < 24
.
(Of course,
array is a really weird name for the size and
size is a really weird name for an array....)
You also don't really need your
n variable, since the values of
n follow right along with the values of
i, so you can just use
i instead of
n.
11 12
|
if (max !=i)
swap (&i, &max);
|
Here, you're just swapping the values of
i and
max -- what you really want is to swap the values
in the array (or should I say "in the 'size' "? :-) ) at positions
i and
max.
So it should be
swap(&size[i], &size[max]);
(for readability)
or
swap(size + i, size + max);
(same thing).
19 20 21 22
|
int findMax (int size [], int array, int i)
{
int min_pos;
min_pos = 0;
|
Since the assumption at this point is that all of the array elements from position 0 to position
i-1 are in their final (sorted) position, this should be
min_pos = i;
instead, because we're trying to find the minimum of the
rest of the array (which goes from
i to
array-1).
Fix all of those and your code
should work.