/** * 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. */ /** * * another variant of Merge */ //-------------------- public class Merge1 extends Sequence { private long hd2; private Sequence s1, s2; public Merge1(Sequence s1, Sequence s2) { this.s1 = s1; this.s2 = s2; hd2 = s2.next(); } public long next() { long res; res = s1.next(); if ( res > hd2 ) { // swap sequences and lookahead Sequence s3; s3 = s1; s1 = s2; s2 = s3; long hd1; hd1 = res; res = hd2; hd2 = hd1; } return res; } } //--------------------