i need to place the minimum number in the inition of the sorted array (i did it) and then to sort other by size .please help me in the first function ..where is the mistake?
thanks a lot
#include <iostream>
#include <stdlib.h>
using namespace std;
#define SIZE 10
int index_of_min(int arr2[ ], int start, int end)
{
if (start == end) //condition for stopping the function and returning the start
return start;
if( arr2[start] < arr2[end] )
return index_of_min( arr2, start, end-1 );
return index_of_min( arr2, start+1, end );
}
void selection_sort (int arr[ ], int start, int end)//that function will find the minimum in the array
{
int tmp = arr[0];//swaping
The call to function selection_sort() should use the defined constant SIZE rather than some particular number.
The function selection_sort receives input parameters start and end, but ignores them and instead uses hard-coded values of 0 and 9.
The swapping operation calls function index_of_min twice which is inefficient, and potentially error-prone, since the array has been modified before the second call.
And finally, selection_sort needs to call itself recursively.