Hi all..
I'm looking for the solution of the following problem..!
I need to write a recursive function that has as arguments an array of characters and two bounds on array indices. The function should reverse the order of those entries in the array whose indices are between the two bounds. For example, suppose that the array is :
a[5] = “abcde”;
and the bounds are 1 and 3. Then after the function is run the array elements should be “adcbe”.
Embed the function in a program and test it. To simplify grading, set up your character array as the whole alphabet:
char array[]=“abcdefghijklmnopqrstuvwxyz”;
And allow the user to specify bounds. Be sure to test our program using bounds that have both an even and an odd number of characters between them
Hope someone will help me with this.... Thanks in Advance.
Regards
The function you need to write is
// "a" is the array of characers
// "first" and "last" are the lower and upper bounds on the indices.
void reverse_interval(char *a, int first, int last) {
reverse(a+first, a+last);
}
void reverse(char *first, char *last) {
// check if the pointer to the first character is before the pointer to the last character
// otherwise return from the function
// swap the *first and the *last characters
// call the function recursively with first+1 and last-1 parameters
}