To solve this problem, we need to understand the concept of backtracking.
According to the backtracking algorithm:
- Fix a character in the first position and swap the rest of the character with the first character. Like in ABC, in the first iteration three strings are formed: ABC, BAC, and CBA by swapping A with A, B and C respectively.
- Repeat step 1 for the rest of the characters like fixing second character B and so on.
- Now swap again to go back to the previous position. E.g., from ABC, we formed ABC by fixing B again, and we backtrack to the previous position and swap B with C. So, now we got ABC and ACB.
- Repeat these steps for BAC and CBA, to get all the permutations.

Algorithm
- Define a string.
- Fix a character and swap the rest of the characters.
- Call the generatePermutation() for rest of the characters.
- Backtrack and swap the characters again.
Input:
char str[] = "ABC"
Output:
All the permutations of the string are:
ABC
ACB
BAC
BCA
CBA
CAB
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: