Subject: Re: need help writing function to find largest value of a list!
From: (Rob Warnock)
Date: 5 May 2001 04:12:13 GMT
Newsgroups: comp.lang.scheme
Message-ID: <9cvuit$5ndia$>
Chez <> 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.
  All done.

- 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
SGI Network Engineering		<URL:>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA