## In most languages there is a function already implemented.

In C++

```
string s("abcd");
next_permutation(s.begin(),s.end());
cout<<s;
```

will give

```
abdc
```

Note that when a string is already the lexicographic largest,

`next_permutation`

returns 0 and hence doesn't loop forever if given in a while loop.