Conflict in returning a value through a recursive function
Hello,
I need to write a recursive function, which gets as an input the
address of an array of numbers and it's size, and returns the size of
the longest continuous increasing sub-sequence in it.
There's also a limitation, that I can't use loops or other functions.
I also can't use pointers to outer variables, because I'm not supposed
to change the main function.
So far I've managed to make this work only for the case in which
two sub-sequences are separated by only 1 number which breaks the sequence, and of course the easy case in which all of the array is an increasing sequence or it's starting to increase from a certain point and then stops.
The more complicated case, is when I've got for example this array:
Code:
{1, 2, 3, 0, 0, 4, 5, 6}
Here the output should be 4 ,
but no matter from which direction the recursive function goes, left to right
Code:
(function(address+1, size-1))
or right to left
Code:
(function(address, size-1))
, I don't know how can I both return the size of the largest previous sub-sequence found, and also start counting the next possible sub-sequence and comparing them, without increasing the largest size already found.
So what I'm actually asking for is help with the algorithm that can solve the more complex case. I would like to figure out the code myself, but I'm having trouble thinking of a successful recursive algorithm.