/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * * f1 and f2 are merged: * e.g. 1 3 5 7 5 3 1 100 ... * and 1 2 4 8 4 2 1 100 ... * --> 1 1 2 3 4 5 7 5 3 1 8 4 2 1 100 * * good for sorting 2 monoton sequences */ //-------------------- public class Merge extends Sequence { private long hd1, hd2; private Sequence s1, s2; public Merge(Sequence s1, Sequence s2) { this.s1 = s1; this.s2 = s2; hd1 = s1.next(); hd2 = s2.next(); } public long next() { long res; if ( hd1 < hd2 ) { res = hd1; hd1 = s1.next(); } else { res = hd2; hd2 = s2.next(); } return res; } } //--------------------