← Back

Problem 4.2 Print all Permutations of a String

Introduction

The problem is closely related to 4.1 but with important differences in implementation.

Once again the problem specification is simple: given a string \( s \), of length \( n \), print all \( n! \) permutations of the characters of \( s \) (in no particular order).

Examples

Input:

\( s = 1234 \)

Output: (printed on screen)

1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321

Implementation

The following code contains two function prototypes (to be implemented by you), and a main that tests them.