This is not working for dictionary order (larger)
You have done 2 mistakes
-
you have to swap after function call as well
you have swap only once -
The output strings must be lexicographically sorted.
so first store them and then sort -
you have to print all permutation less than given string
so in compare function also change comparision sign
Modified Code