Chez <firstname.lastname@example.org> wrote:
| I'm trying to write a function to find the largest number from a given
| list. I know Scheme has a function max that gives the max back. I dont
| want to use that but make the function without using it. Any pointers??
First, write your own "max" that works with just two arguments.
Given that, what could you do if someone handed you number which was
a guess at the maximum, plus a list of possibly-larger values? Well...
- If the list is empty, your guess is as good as it gets, so return that.
- If the list isn't empty, then the first element on the list is either
bigger than the current guess or not, so your new guess is the maximum
of your current guess and said first element. Now figure out what to do
with that new guess and the rest of the list...
Rob Warnock, 31-2-510 email@example.com
SGI Network Engineering <URL:http://reality.sgi.com/rpw3/>
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA