Monday, April 16, 2012

Challenge 059’s Solution

The method recur will always return the greatest int value in the list x. The program first creates an int variable t. It then checks if n, the size of x, is just 1, in which case the greatest value is the zeroth element of x. Otherwise, the method sets t as equal to the second-to-last element of x using recursion. This is repeated because of recursion until there is a t value equal to the zeroth element of x. Element 0 of x, aka t, is compared to element 1 of x. The greater of the two values is returned as the result of the last recur method, which becomes the next t. This continues until the end of the original recur method, where the greatest int value in the list x is returned.
 
−Phoenix

1 comment: