This recursive functions works this way...
Code:
void recurseReverse(vector<int>& aVec, intvec_sz start, intvec_sz end)
{
if ((end - start) <=1)
return;
else
{
int temp = aVec[end - 1];
aVec[end - 1] = aVec[start];
aVec[start] = temp;
recurseReverse(aVec, start + 1, end - 1);
}
}
but not this way...
Code:
void recurseReverse(vector<int>& aVec, intvec_sz start, intvec_sz end)
{
while((end - start) > 1)
{
int temp = aVec[end - 1];
aVec[end - 1] = aVec[start];
aVec[start] = temp;
recurseReverse(aVec, start + 1, end - 1);
}
}
I assume that in the latter code, when it found that the end - start is one, it would return from the function