I wrote the following C++ code to generate the next inverse alphabet order of the input string. However I got error saying: no matching function for call to 'reverse': candidate template ignored: deduced conflicting types for parameter '_BidirectionalIterator' ('std::__1::basic_string' vs. 'int') reverse(_BidirectionalIterator __first, _BidirectionalIterator __last). I couldn't understand the error message and don't know how to adjust it. Could anyone help me out here? Thanks!
#include<iostream>
#include<string>
using namespace std;
string gen(string A,int n){
int i, j;
for(i= n-1;(i > 0 && A[i-1]<A[i]);i--)
; // empty statement
if (i == 0)
return 0;
for (j = i+1; j < n && A[i-1] > A[j]; j++)
; // empty statement
swap(A[i-1],A[j-1]); // swap values in the two entries
string subline =A.substr(i,n-i);
subline=reverse(subline,n-i);
A=A.substr(0,i-1)+subline;
return A;
}
void swap(int &a,int &b)
{
int temp=b;
b=a;
a=temp;
}
string reverse(string k,int length)
{
for(int m=0;m<length/2;m++)
{
char temp=k[length-1-m];
k[length-1-m]=k[m];
k[m]=temp;
}
return k;
}
int main(void)
{
cout<<"Please enter a string"<<endl;
string arrayperm;
cin>>arrayperm;
int length=arrayperm.length();
string newone=gen(arrayperm,length);
cout<<"The new array is: "<<newone<<endl;
return 0;
}