Displaying combinations of string without repetition with the help of circular queue

Input :
n= 4
PRSW

Output :
RSWP
SWPR
WPRS
PRSW
Looks hard. What have you tried?
so the order is fixed and the starting point varies.
easy enough. there are probably cleaner ways, but just iteration gets it done

vector<char> buff(4) = {'P','R','S','W'}; //You will want to read all this in

for(out = 0; out < buff.size(); out++)
{
for(in = 0; in < buff.size(); out++)
{
cout << buff[ (out+in)%buff.size()];
}
cout << endl;
}

so, basically, we used sensible iteration to make a standard vector look like a circular queue. you can cook up a full blown data structure for this instead, but its a lot of trouble for not much real gain.
Last edited on
Topic archived. No new replies allowed.