Untitled

mail@pastecode.io avatar
unknown
c_cpp
9 days ago
583 B
1
Indexable
Never
int findMinElementIndex( const std::vector< int >& vec, int start )
{
    int minIndex = start;

    for( int i = start + 1; i < vec.size(); ++i )
    {
        if( vec[ i ] < vec[ minIndex ] )
        {
            minIndex = i;
        }
    }

    return minIndex;
}

std::vector< int > sort( const std::vector< int >& vec )
{
    std::vector< int > result = vec;

    for( int i = 0; i < result.size(); ++i )
    {
        int minIndex = findMinElementIndex( result, i );
        std::swap( result[ i ], result[ minIndex ] );
    }

    return result;
}
Leave a Comment