Documente Academic
Documente Profesional
Documente Cultură
Writeafunctionthatdoesthefollowing:
Input:AnarrayAoflengthN.NisanevennumberandN>=2.
Output:AreorderedarrayB.ThefirsthalfofBcontainsAselementswithevenindices.The
secondhalfofBcontainsAselementswithoddindices.Convention:thefirstindexofanarrayis
0(andthusitisanevennumber).
Input1:[4,8,12,16]
Forthisarray,theindicesandthevaluesareasfollows:
Index
Value
12
16
Thus,theoutputisasfollows:
Expectedoutput1:[4,12,8,16]
ADDITIONALTESTCASE
Input2:[1,2,3,4,5,6,7,8,9,10]
Expectedoutput2:[1,3,5,7,9,2,4,6,8,10]
TASK
Writearecursivefunctioninaprogramminglanguageofyourchoice(asifyouarewriting
realcodetobeusedonaproductionserver)fortheaboveproblem
Inadditiontothemainfunction,youarefreetowritehelperfunctions(ifneeded)
Thecodeshouldhaveasfewlinesaspossible(butitshouldstillbeclearandreadable)