Some recursion help...Please
843789Sep 21 2009 — edited Sep 22 2009I'm currently working on a small programming project that incorporates a recursive function implementation and I was hoping to get some suggestions/help.
The program involves finding the minimum value in a generic ArrayList.
The declaration is as follows:
ArrayList<AnyType> theArray = new ArrayList<AnyType>();
int size = 0;
I know that size can be found with size() method but we are limited in the methods that we can use. I was incrementing/decrementing size as I add/remove elements.
The challenge is trying to put together a recursive method getMin() that can return the minimum value of the comparables added to theArray. I know methods to do this recursively when parameters can be passed but without a parameter I'm really stumped.
I was thinking that I should include add type of pointer variables (start, end) to class declaration but I'm not sure it that really helps me.
If the arraylist containted Integers (15,5,19,6) I know that I should be comparing 15 with the minimum of sub-array (5, 19, 6) but I don't want to modify the original array by deleting items. Is it possible to create a duplicate arraylist in the midst of the recursive call?
Any thoughts or suggestions are appreciated.