Creating a permutation function

I'm creating a method to calculate all possible permutations of a string. I know the problem is with my for loop, but I don't know where to go next. I'm not looking for a straight up answer, just to be pointed in the right direction. My method is below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vector <string> getPerm(string w)
{
    vector<string> v;
    if(w.length() <= 1)
    {
        v.push_back(w);
        return v;
    }
    else
    {
        for(int i = 1; i < w.size(); i++)
	{
	    return getPerm(w.substr(1));
	}
    }
}


I need to return all possible permutations in a vector. My professor didn't show us his code, but he said his method was only about 15 lines.
Last edited on
use the next_permutation function in STL Algorithms?

http://www.cplusplus.com/reference/algorithm/next_permutation/
@tntxtnt: The point is for me to write it myself.
Last edited on
Topic archived. No new replies allowed.