#include <iostream>
#include <cstdlib>

template <typename T> void selection_sort(T* begin, T* end, unsigned pos = 0u) 
{
    if(begin != end)
    {
        for(int i = pos; i < (end - begin) + pos; i++)
        {
            if(begin[pos] > begin[i]) std::swap(begin[pos], begin[i]);
        }
        selection_sort(begin + 1, end, pos);
    }
}

int main(int argc, char** argv)
{
    int itens[] = {1, 3, 5, 2, 4};
    
    selection_sort(&itens[0], &itens[5], 0);
    
    for(int i = 0; i < 5; i++)
    {
        std::cout << itens[i] << " ";
    }
    
    return 0;
}
