Next permutation

how we will check the end condition of next permutation

Store, first permutation in a string. Let it be S. and then check until & unless your next permuataion is equal to S. You print that using a while loop.