- Write a function set < vector < int > > permute(vector
< int > l, vector< int > post) which permutes the values
in l and appends to the end of them the values of post.
This is the difficult part: if you return such a set, then it is
_already_ sorted for you, it is simply a matter of counting n
elements into it.
This function must be recursive (and function that runs in O(n!), or
even O(2n) is going to be recursive.)
The base case is if l is empty: just return the set containing
post.
OTHERWISE, loop through the elements of l, remove the current
element from l, add it to the end of post, call permute,
and add the results to the return value. It is best to make temp
copies of l and post to not cause trouble. Might even
make i and post const.
- If you really can't figure out how to do this, try looking at the
same code written in Python.
Understand the algorithm, and then deal with the STL separately.