Cpp implementation of Next Permutation