1
2
3
4
5
6
7
8
9
10
11
12
13public
14class Merge extends Sequence {
15 private
16 long hd1, hd2;
17
18 private
19 Sequence s1, s2;
20
21 public
22 Merge(Sequence s1, Sequence s2) {
23
24 this.s1 = s1;
25 this.s2 = s2;
26
27 hd1 = s1.next();
28 hd2 = s2.next();
29 }
30
31 public
32 long next() {
33 long res;
34
35 if ( hd1 < hd2 ) {
36 res = hd1;
37 hd1 = s1.next();
38 } else {
39 res = hd2;
40 hd2 = s2.next();
41 }
42
43 return res;
44 }
45}
46
47
48