I would like to know how I could achieve a simple function "length" that returns the length of a given array in a recursive manner.
This seems pretty easy with Prolog, but I'm not sure how to do it with C++, precisely, how to divide the arrays in an efficient way.
Example could be:
int lenght(*int arr)
{
...
}
int main()
{
int arr[5] = {1,2,3,4,5};
cout << "Length is: " <<length(arr)
}
In Prolog I would use something like tow cases, one for the base case, and another for the recursive case
length([], 0).
length([Head|Tail], Length) :- size(Tail,TailListLength), Length is TailListLength+1.