This is not working for dictionary order (larger)

You have done 2 mistakes

  1. you have to swap after function call as well
    you have swap only once

  2. The output strings must be lexicographically sorted.
    so first store them and then sort

  3. you have to print all permutation less than given string
    so in compare function also change comparision sign

Modified Code