Tricky permutations recursion

I am able to print the required permutations but they are not in lexicographical order

@sam15jain
As for the sorting , you can make a vector of strings and store each output string in that vector. That is , instead of printing them in Line No. 7 , store them into a vector of strings which is declared in global scope.
Say this vector is named as v.
Once you are done with your recursive calls , call the sort( ) on v as
sort(v.begin() , v.end() ) ;
After that simply print the elements of vector v as they have been sorted.