Hey, I am having trouble implementing a c++ function that will allow the user to enter a lower and upper bounds and reverse everything in a char[] in between the bounds, so if array is,
char[] = {'A','B','C','D','E'};
and the user input was 1 and 4 for 1 as the lower bounds
and 4 being the upper bounds, then the output should be,
ADCBE
I know I am getting close with the code I have right now,
but I am not sure where my logic is incorrect...
---------------------------
the code I have for this function so far is,
void reOrder(char a1[], int start, int end){ // NOT WORKING
char temp;
if(start > end) {
cout << " " << endl;
for(int i = 0; i < 5; i++){
cout << a1[i] << " ";
}
cout << "" << endl;
return;
}
else{
temp = a1[end];
a1[end] = a1[start];
a1[start] = temp;
reOrder(a1, ++ start, -- end);
}
}
and my output is incorrect,
OUTPUT:
AEDCB
If anyone could help me figure this out I will greatly appreciate it, I am trying to learn recursion.