O'Reilly logo

A Common-Sense Guide to Data Structures and Algorithms by Jay Wengrow

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deletion

Deletion from an array is the process of eliminating the value at a particular index.

Let’s return to our original example array, and delete the value at index 2. In our example, this would be the "cucumbers".

Step #1: We delete "cucumbers" from the array:

images/chapter2/understanding_arrays_Part16.png

While the actual deletion of "cucumbers" technically took just one step, we now have a problem: we have an empty cell sitting smack in the middle of our array. An array is not allowed to have gaps in the middle of it, so to resolve this issue, we need to shift "dates" and "elderberries" to the left.

Step #2: We shift "dates" to the left:

Step #3: We shift "elderberries" to the left: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required