Tail Recursive Merge


(defun merjtr (x y) (nreverse (merjtrb x y '())))
(defun merjtrb (x y result)
 (if (null x)
   (if (null y)
       result
       (merjtrb x (rest y) (cons (first y) result)) )
   (if (or (null y)
           (< (first x) (first y)))
       (merjtrb (rest x) y (cons (first x) result))
       (merjtrb x (rest y) (cons (first y) result)))))


  1> (MERJTR (3 7 9) (1 2 4))
    2> (MERJTRB (3 7 9) (1 2 4) NIL)
      3> (MERJTRB (3 7 9) (2 4) (1))
        4> (MERJTRB (3 7 9) (4) (2 1))
          5> (MERJTRB (7 9) (4) (3 2 1))
            6> (MERJTRB (7 9) NIL (4 3 2 1))
              7> (MERJTRB (9) NIL (7 4 3 2 1))
                8> (MERJTRB NIL NIL (9 7 4 3 2 1))
                <8 (MERJTRB (9 7 4 3 2 1))
              <7 (MERJTRB (9 7 4 3 2 1))
            <6 (MERJTRB (9 7 4 3 2 1))
          <5 (MERJTRB (9 7 4 3 2 1))
        <4 (MERJTRB (9 7 4 3 2 1))
      <3 (MERJTRB (9 7 4 3 2 1))
    <2 (MERJTRB (9 7 4 3 2 1))
  <1 (MERJTR (1 2 3 4 7 9))

Contents    Page-10    Prev    Next    Page+10    Index