Question: Consider the following class: that creates a new sequence, appending this and the other sequence, without modifying either sequence. For example, if a is 1

Consider the following class: 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 149 16 9749 11 without modifying a or b. Add a method 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 194794 16 9 11 without modifying a or b. Add a method that merges two sorted sequences, producing a new sorted sequence. Keep an index into each sequence, indicating how much of it has been processed already. Each time, append the smallest unprocessed value from either sequence, then advance the index. For example, if a is 1 4 9 16 and b is 479911 then a.mergeSorted(b) returns the sequence 144799911 16 without modifying a or b
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
