Consider the following class: public class Sequence { private ArrayList values; public Sequence() { values = new ArrayList(); } public void add(int n) { values.add(n); } public String toString() { return values.toString(); } } 3.1. Add a method public Sequence append(Sequence other) that creates a new sequence, appending this and the other sequence, without modifying either sequence. For example, if a is 1 4 9 16 and b is the sequence 9 7 4 9 11 then the call a.append(b) returns the sequence 1 4 9 16 9 7 4 9 11 without modifying a or b. 3.2. Add a method public Sequence merge(Sequence other) that merges two sequences, alternating elements from both sequences. If one sequence is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer sequence. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then a.merge(b) returns the sequence 1 9 4 7 9 4 16 9 11 without modifying a or b. 3.3. Add a method public Sequence mergeNoDuplicates(Sequence other) that merges two sorted sequences, producing a new sequence in strong increasing order. You must assume that both sequences are in strong increasing order (no duplicates). For example, if a is 1 4 9 and b is 2 4 6 9 16 21 then a.mergeNoDuplicates(b) returns the sequence 1 2 4 6 9 16 21 without modifying a or b.
Get Free Quote!
326 Experts Online