while (r != eof && s != eof) { if (r.val ≤ s.val) { output(r.val); next(r); } else { output(s.val); next(s); } } while (r != eof) { output(r.val); next(r); } while (s != eof) { output(s.val); next(s); }