Spiffy
2009-11-06 22:11:48 UTC
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".
char *reorder(char ptr[], int b1, int b2)
{
if( b2-b1 <= 1)
{
cout << "\n\nEnd Reached\n\n";
return ptr;
}
char swap;
swap = ptr[b1];
cout << ptr[b1];
ptr[b1] = ptr[b2];
cout << ptr[b1];
ptr[b2] = swap;
return reorder(ptr,b1++,b2--);
}
I get the error Unhandled exception at 0x00411ad9 in Lab9.exe: 0xC00000FD: Stack overflow. and it points to the beginning bracket of the function