+ 19

I am not able to understand how thies code m[i-1]=m[i];is 👉 deleting an element from an array useing for loop?

can some one explain me thies 👆 https://code.sololearn.com/cTuPAI8J7bTj/?ref=app

28th May 2018, 12:26 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
3 Respuestas
+ 4
imagine you want to remove 3rd element from this array {1, 2, 3, 4, 5} inorder to remove 3rd element, we need to shift 4th, 5th left once result would be {1, 2, 4, 5} m[i-1] = m[i] does this job for you i.e it shifts [i]th element to the [i-1]'s place
28th May 2018, 12:53 PM
‎ ‏‏‎Anonymous Guy
+ 16
thank you Bahubali 😃and Sreejith
28th May 2018, 2:08 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
+ 3
in line 19 u are assigning m[2]=m[3] that's why it delete the m[2] and then. n-- make n=4
28th May 2018, 12:50 PM
Bahubali
Bahubali - avatar