I have an array, and the user can insert a string.

And I have this code:

int main(){
  char anagrama[13];
  cin >> anagrama;
  for(int j = 0; j < strlen(anagrama); j++){
    cout << anagrama[j];
    for(int k = 0; k < strlen(anagrama); k++){
      if(j != k)
        cout << anagrama[k];
    }
    cout << endl;
  }
}

The problem is that I need all permutations of the string in sorted order.

For example if the user write: abc, the output must to be:

abc
acb
bac
bca
cab
cba

and my code doesn't show all permutations, and not sorted

Can you help me?

I need do the implementation without a function already implemented.

I think with a recursive function, but I do not know how.

This is an example: http://www.disfrutalasmatematicas.com/combinatoria/combinaciones-permutaciones-calculadora.html without repetition and sorted

Edit
Report