I am having a problem with my code, it is suppose to be rearranging the characters inside the array, but every time i enter the lower bounds (x) and upper bounds (y), i rearranges the wrong alphabets. Here is my code
int main()
{
char a[5]={'A','B','C','D','E'};
int x, y;
cout << "Input bounds for array" << endl;
cin >> x >> y;
rever(a, x, y);
system("pause");
return 0;
}
void rever(char a[], int x, int y)
{
char reorder;
if( x >= y)
{
for(int i = 0; i < 5; i++){
cout << a[i];
}
cout << endl;
return;
}
else{
reorder = a[x];
a[y] = a[x];
a[x] = reorder;
rever(a, ++x, --y);
}
}
I enter 1 and 4 and my output is ABCCB