Answer to Question 28-1

Here is a plan, shown for example smallest([5,3,1,4]).

 p      s 
[3,1,4]    5
[1,4]    3
[4]    1
[ ]    1

Here is an algorithm based on that plan.

  int smallest(ConstList L)
  {
    int s = head(L);
    for(ConstList p = tail(L); !isEmpty(p); p = tail(p))
    {
      s = min(s, head(p));
    }
    return s;
  }