Which is faster? someCondition has the same probability of being true as it has of being false.
Insertion:
arrayList = Array('apple', 'pear','grape') if someCondition then ' insert 'banana' element end if
Deletion:
arrayList = Array('apple','banana','pear','grape') if not someCondition then ' remove 'banana' element end if
It looks like it depends purely on the implementation of Insert and Remove. So which, in general, is faster? I’m leaning toward insertion because I’ve read that one can use CopyMemory to insert without looping. Is this the same for deletion? Does anyone have an example?
Edit: This is VB6, not VB.NET. For display reasons, I have to use insert rather than append.
For a delete, every item after the removed item must be shifted down.
For an Insert, space must be found for the new item. If there is empty space after the array that it can annex, then this takes no time, and the only time spend is more each item after the new item up, to make room in the middle.
If there is no available space locally, a whole new array must be allocated and every item copied.
So, when considering adding or deleting to the same array position, inserting could be as fast as deleting, but it maybe much longer. Inserting won’t be faster.