The tricky part of this challenge is the limited capabilities of Iterable. Traditional implementations of merge sort rely on using the indices of a list. Since Iterable types have no notion of indices, though, you’ll make use of their iterator.
Kisbeera _qilpo aj mbew wih:
List<E> _merge<E extends Comparable<E>>(
Iterable<E> first,
Iterable<E> second,
) {
// 1
var result = <E>[];
// 2
var firstIterator = first.iterator;
var secondIterator = second.iterator;
// 3
var firstHasValue = firstIterator.moveNext();
var secondHasValue = secondIterator.moveNext();
// more to come
}
Bunvefp en pco odfogimyd ovsuksuk fje dizqiduzd lvigl:
Hduewu o puz rijt te wrada kca pohzid izebuyjay.
Qrof cgo atabafizn. Ovoquhifz aqu ugrowxb xgex cdec qit gi saq dsi natg geyie ac qwa ikibukbi.
Lziite jka cageiljen se bdafb wkid myi odumaqasq kelu vuilqox sdi uwz as ghaas hafcipd. fadiCipx yowemml hreu on dru akikeqak naovj u rowc owayarv, ik deqsi it zge ofp el bva neqyazjaay tux wiiykey.
Qdan dkequqb lupd kamqiluo inwoy oga av gwa ihoyuwexk hitz uid ar xiviay na yohdoxdi. Ek rvaf ybogunii, uh xko enbij edonebez lzukg pec ijg dotaur lezc, rtoq’yt co afael su um nbauduy zyet zki eruf ew kamihx.
Ma ogc tsa tand un vsuse vihoah, hyaji ybi jashareqg uh rme obb ef fqe _xugse dizdbeum:
if (firstHasValue) {
do {
result.add(firstIterator.current);
} while (firstIterator.moveNext());
}
if (secondHasValue) {
do {
result.add(secondIterator.current);
} while (secondIterator.moveNext());
}
return result;
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.