A non recursive version of generating permutation implementing the iterator pattern