STL provides a simple and a very useful function called next_permutation which takes a sequence and generates permutation in a lexicographical order. This function does not even generate repeated permutations when some of the elements of the sequence are repeated. So this makes it much more useful. Suppose we write a normal recursive function for generating permutations we have to take special care of the repeating characters.
Following is the algo for the next permutation.
Consider a permutation a1,a2,a3,... an.
find a pointer i such a(i)< a(i+1). Once u find this pointer i , repeat again from the right end of the array to find a value >= a(i). Let this value pointed by the pointer j.
Now swap (a(i) , a(j)) and then reverse array from a(i+1) to a(n).
This permutation will be the next permutation. The order of this Algo is O(n) where n is the number of elements of the array. The condition a(i) < a(i+1) is responsible for non repetition of permutations when a element occurs more than once in the array.