title: How do I find largest number in List in SML
body: <blockquote>
    <p>We want to find the largest value in a given nonempty list of
    integers.   Then we have to compare elements in the list.  Since data
    values are given as  a sequence, we can do comparisons from the
    beginning or from the end of  the list.  Define in both ways. a) 
    comparison from the beginning b)  comparison from the end   (How can
    we do this when data values are in a list?)</p>
  </blockquote>
  
  <p>What I have done is find the largest number by comparison from the beginning.</p>
  
  <p>How can I do it from the end? What logic should I apply?</p>
  
  <p>Here is my code for comparing from the beginning.</p>
  
  <pre><code>- fun largest[x] = x
  = | largest(x::y::xs) =
  = if x&gt;y then largest(x::xs) else largest(y::xs)
  = | largest[] = 0;
  val largest = fn : int list -&gt; int
  
  
  output
  
  - largest [1,4,2,3,6,5,4,6,7];
  val it = 7 : int
  </code></pre>