This is exactly the reason why arrays are a bad choice for a collection of items which might be deleted: inside the computer's memory it goes as follows:
int a[1000];
for (int i=0;i<1000;i++){
a[i] = i;
}
What does this do:
int a[1000];
You might think this is just telling the computer that you will use an array of size 1000, and that's it, but there's a lot more to that: at this moment your computer reserves 1000 places where all of those entries can be stored. This is also a reason why you need to pay attention not to go to far here: imagine you put one billion or even one trillion as a size, you might blow up the memory of your computer, just using that one line.
Once all those places are reserved, you can occupy them with the values you want, but about that deleting, there's a catch: as mentioned by @Hadeel you'll need to shift the next entries in your array in order not to have a hole in your array. In top of that, there still will be 1000 (or more) memory addresses, reserved for your one array.
You might reduce this in memory, by re-allocating your array, but this is dangerous, and furthermore why would you?
Lists, however, are far easier: you just declare them, they don't reserve a whole bunch of memory and you can add and delete as much as you want without the whole shifting process. However, accessing the n
th entry in your list requires you to run from the first entry to that n
th one in order to find it.
So let's have a look at the speed of both:
array linked list
access an entry O(1) O(n)
add an entry O(1) O(1)
delete an entry O(n) O(1)
Good luck