In my program below, I am having problems running my program. The error I receive is "could not convert `nextPermutation(((char*)(&elements)), n)' to `bool'" I just want to print out the permutation of ABC. Will someone please check my nextPermutation function to see if everything is correct. I know there a function next_permutation function in #include <algorithm>, but I want try it manually.
Example Input:
"Enter the string"
A,B,C
Output:
{a, b, c}
{a, c, b}
{b, a, c}
{b, c, a}
{c, a, b}
{c, b, a}
Program:
#include <iostream>
using namespace std;
void nextPermutation(char elements[], int n);
int main()
{
char elements[100];
int n = 3;
cout<<"Enter the string"<<endl;
for (int i = 0; i<n; i++)
{
cin>>elements;
}
do
{
cout<<elements;
}while(nextPermutation(elements,n));
system("PAUSE");
return 0;
}
void nextPermutation( char elements[], int n )
{
char j = n-1;
int k,r,s;
while (elements[j] > elements[j+1])
{
j = j-1;
}
k = n;
while (elements[j] > elements[k])
{
k = k-1;
}
swap(elements[j],elements[k]);
r = n;
s = j+1;
while (r > s)
{
swap(elements[r],elements[s]);
r = r-1;
s = s+1;
}
}