### Recursion Help

I am in need of some help with Recursion. I need to find the largest element in a vector of integer values. The problem is, I don't know where to start. I feel like I am a lost puppy and this is only the first week of the new term.

 ``123456789`` `````` Recursion is the act of a function calling itself to make the problem smaller (easier to deal with/solve). From the problem in my book, I want to use: int maximum(vector values). (I am also researching vectors because I for them too :P). ** The hint is: "Find the largest element in the subset containing all but the last element. Then compare that maximum to the value of the last element".``````

So, if I am correct, the idea is that we are going to assume that the last element is the largest and then compare each element to that last element. So the `if` statement could be:`if{a[i] > a[5] return a[i]}`, where a[i] is every number besides that last one, and if it's bigger then we return that number as the largest?

I'll work on that thought and post back in a bit. Any guidance/help would be great!

David
I feel stupid: int maximum(vector<int> values) is the function to find the maximum?? The function type is int, name is maximum with arguments of vector<int> values (which will be defined in main?)
 @toonhead85 So, if I am correct, the idea is that we are going to assume that the last element is the largest and then compare each element to that last element.

All elements can be less than the last. In this case you will not find the maximum among all elements excluding the last.
Last edited on
Topic archived. No new replies allowed.