0

I have to remove an element from index = 7 from an array and then move the rest of the elements to the positions 7, 8, 9, and so on.. i looked in my book but i cant find the remove code... does anyone know how i can remove the element and then move the rest?

thanks

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Nichito
0

there's another solution a bit more complicated than the one from salem (wich is pretty simple, nonetheless pretty accurate to your question), but i'd rather create a temporary array, transer the files from array1 into array2, delete array1, create (again) array1[size-1], and transfer again all information, but the element you wish to remove.

This is pretty useful when you use large arrays and you wish to print them or use them in other processes (with a loop) that could/will use the entire array... this way, you have the amount of elements you need in your array, and you donĀ“t have to worry about the last elements being the same...

This may also work when adding an element to the array, except that when you create the array again, the size must be [size+1], and then you read the information for the last element...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.