0

Hi guys i need to delete item from arra and print new array, what wrong?

https://code.sololearn.com/c88qNdrw4lJl/?ref=app

7th Jul 2021, 8:42 PM
Olka Berkovich
Olka Berkovich - avatar
8 Respuestas
+ 3
what is the expected input? index of item to be deleted or value of item to be deleted? in second case, would you delete only the first encountered value matching or all values matching?
8th Jul 2021, 12:26 AM
visph
visph - avatar
0
Thanks a lot guys, visph i want to delete by index
8th Jul 2021, 9:23 PM
Olka Berkovich
Olka Berkovich - avatar
0
so, if x is the index, you may test if it is valid (0 <= x < length), and iterate i from x+1 to length (not included), and only set arr[i-1] = arr[i]... do not forgot to update length ( = length-1), to not use more than valid index ;)
8th Jul 2021, 9:28 PM
visph
visph - avatar
8th Jul 2021, 9:45 PM
visph
visph - avatar
0
visph thanks a lot but a code all time print only else
9th Jul 2021, 7:40 AM
Olka Berkovich
Olka Berkovich - avatar
0
We dont entry to if, and here not print anything, its not work correctly...
9th Jul 2021, 2:26 PM
Olka Berkovich
Olka Berkovich - avatar
- 1
Olka Berkovich what do you mean by "a code all time print only else"?
9th Jul 2021, 10:22 AM
visph
visph - avatar
- 1
it works correctly for me, if you provide valid input (index between 0 to 5 inclusive)... it only execute else for invalid index ^^
9th Jul 2021, 4:15 PM
visph
visph - avatar