I copied this progrm from "Jumpin into C++" by Alex Allain.However when icopied the whole and ran the progrm an error is coming- undefined refrence to -findSmallestremaingElement in -Int index. could some one help me with this. no other error is shown.thanks
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int findSmallestRemainingElement (int array[], int size, int index);
void swap (int array[], int first_index, int second_index);
void sort (int array[], int size)
{
for ( int i = 0; i < size; i++ )
{
int index = findSmallestRemainingElement( array, size, i );
swap( array, i, index );
}
The Function Used Above For Sorting Is False:I could Help you bit By Giving You the correct Function of Sorting and Function Of Swapping which is USed in Sorting Which Will Help You.
#include <iostream>
#include <algorithm>
usingnamespace std;
int findSmallestRemainingElement (int array[], int size, int index)
{
return min_element(array+index, array+size) - array;
}
void swap (int array[], int first_index, int second_index)
{
swap(array[first_index], array[second_index]);
}
void sort (int array[], int size)
{
for ( int i = 0; i < size; i++ )
{
int index = findSmallestRemainingElement( array, size, i );
swap( array, i, index );
}
}