Write a method called interleave that accepts two
Write a method called interleave that accepts two ArrayLists of integers a1 and a2 as parameters and inserts the elements of a2 into a1 at alternating indexes. If the lists are of unequal length, the remaining elements of the longer list are left at the end of a1. For example, if a1 stores [10, 20, 30] and a2 stores [4, 5, 6, 7, 8], the call of interleave(a1, a2); should change a1 to store [10, 4, 20, 5, 30, 6, 7, 8]. If a1 had stored [10, 20, 30, 40, 50] and a2 had stored [6, 7, 8], the call of interleave(a1, a2); would change a1 to store [10, 6, 20, 7, 30, 8, 40, 50].
Â
Answers
Status NEW
Posted 26 Apr 2017 04:04 PM
My Price 5.00
-----------
Attachments
file 1493224024-Answer.docx preview (406 words )
W-----------rit-----------e a----------- me-----------tho-----------d c-----------all-----------ed -----------int-----------erl-----------eav-----------e t-----------hat----------- ac-----------cep-----------ts -----------two----------- Ar-----------ray-----------Lis-----------ts -----------of -----------int-----------ege-----------rs -----------a1 -----------and----------- a2----------- as----------- pa-----------ram-----------ete-----------rs -----------and----------- in-----------ser-----------ts -----------the----------- el-----------eme-----------nts----------- of----------- a2----------- in-----------to -----------a1 -----------at -----------alt-----------ern-----------ati-----------ng -----------ind-----------exe-----------s. -----------If -----------the----------- li-----------sts----------- ar-----------e o-----------f u-----------neq-----------ual----------- le-----------ngt-----------h, -----------the----------- re-----------mai-----------nin-----------g e-----------lem-----------ent-----------s o-----------f t-----------he -----------lon-----------ger----------- li-----------st -----------are----------- le-----------ft -----------at -----------the----------- en-----------d o-----------f a-----------1. -----------For----------- ex-----------amp-----------le,----------- if----------- a1----------- st-----------ore-----------s [-----------10,----------- 20-----------, 3-----------0] -----------and----------- a2----------- st-----------ore-----------s [-----------4, -----------5, -----------6, -----------7, -----------8],----------- th-----------e c-----------all----------- of----------- in-----------ter-----------lea-----------ve(-----------a1,----------- a2-----------); -----------sho-----------uld----------- ch-----------ang-----------e a-----------1 t-----------o s-----------tor-----------e [-----------10,----------- 4,----------- 20-----------, 5-----------, 3-----------0, -----------6, -----------7, -----------8].----------- If----------- a1-----------
Not Rated(0)