title: Implementing a min/max function in Scheme
body: <p>I need to write a function for class in Scheme that finds the minimum and maximum value in a list. We are not allowed to use the built in min and max functions. I found a segment of code that finds the max and min values, but for me it outputs the minimum as the head of the list. Here is the code:</p>
  
  <pre><code>(define (minmax lst)
    (cond
      ((null? lst) '())
      ((null? (cdr lst)) (list (car lst) (car lst)))
      (else
       (let ((mmtemp (minmax (cdr lst))) (first (car lst)))
         (cond
           ((&gt; first (car mmtemp)) (cons first (cdr mmtemp)))
           ((&lt; first (car mmtemp)) (list (car mmtemp) first))
           (else mmtemp))))))
  </code></pre>
  
  <p>If I enter:</p>
  
  <pre><code>(minmax '(3 4 6 9 22 203 1 43 8 4))
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>(203 3)
  </code></pre>
  
  <p>When I actually need:</p>
  
  <pre><code>(1 203)
  </code></pre>
  
  <p>I have no experience in Scheme and the lecture slides aren't helping. What needs to change to flip the output order and get the correct minimum value?</p>