Contents    Page-10    Prev    Next    Page+10    Index   

Destructive Merge Function


public static Cons dmerjr (Cons x, Cons y) {
  if ( x == null )
     return y;
   else if ( y == null )
           return x;
  else if ( ((Comparable) first(x))
                        .compareTo(first(y)) < 0 )
          { setrest(x, dmerjr(rest(x), y));
            return x; }
       else { setrest(y, dmerjr(x, rest(y)));
              return y; } }


(defun dmerjr (x y)
  (if (null x)
      y
      (if (null y)
          x
          (if (< (first x) (first y))
              (progn (setf (rest x)
                           (dmerjr (rest x) y))
                     x)
              (progn (setf (rest y)
                           (dmerjr  x (rest y)))
                     y) ) ) ) )