Generating Permutations of a word Alphabetically

For my assignment, I must write a class called Permutation which is used to generate permutations of a word alphabetically. The constructor of the class must accept exactly one argument, the word to scramble.

Relevant Information:
Member function get() returns the current value of the word, and member function next() updates the word to the next one alphabetically.

Usage:
1
2
3
4
Permutation P("abcde");
P.next();
P.next();
std::cout << P.get(); // outputs "abdce" 

If the permutation is the last alphabetically, then next() should produce the first permutation alphabetically.

This is what I have outlined so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Permutation 
{
public:
    Permutation(const std::string&);
    std::string get() const;
    void next ();

private:
    std::string word;
};

Permutation::Permutation(const std::string& s)
{
    word = s;
}

std::string Permutation::get() const 
{
    //insert some code here
}

void Permutation::next()
{
    //insert some code here
}


Please help me complete the program.
Last edited on
Topic archived. No new replies allowed.