Nobody knows what this magic number 30 means in your function
template<typename Comparable>
void selectionSort(vector<Comparable> & toSort)
{
int pos, min, i;
for( pos = 0; pos < 30; ++pos)
{
min = toSort[pos];
for( i = toSort[pos + 1]; i < toSort[30]; ++i)
and even the function itself does not know what this magic number 30 means.
If you are using standard container std::vector
then it has member function size
that can always report how many elements there are in the container.
In any case if you will use size() instead of 30 the code is invalid because the inner loop will access the element with the position equal to size()
for( i = toSort[pos + 1]; i < toSort[30]; ++i)
I think there should be
for( i = pos + 1; i < toSor.size(); ++i)
This condition
if( min != pos)
is also invalid because you are comparing different entities.
The function could be defined the following way
template<typename Comparable>
void selectionSort( std::vector<Comparable> & toSort )
{
for ( std::vector<Comparable>::size_type pos = 0; pos < toSort.size(); ++pos )
{
std::vector<Comparable>::size_type min = pos;
for ( std::vector<Comparable>::size_type i = pos + 1; i < toSort.size(); ++i )
{
if ( toSort[i] < toSort[min] ) min = i;
}
if ( min != pos )
{
std::swap( toSort[min], toSort[pos] );
}
}
}