Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualParadigm Shifter

Posted 28 January 2013 - 03:33 PM

Deleting elements from the middle of an array is possibly the worst use-case for an array data structure, I hope your Prof tells you about that, IF you need preserve the relative ordering of the elements.

SotL's suggestion to move or copy the last element over the deleted one is the best method if the order is unimportant.

If the order needs to be preserved after deletion you should be using a linked list if this is a common use-case for the data. Other data structures such as a set implemented as a red-black tree are good if insertion and deletion is common and the members must be sorted ascending (or descending) at all times.

#1Paradigm Shifter

Posted 28 January 2013 - 03:33 PM

Deleting elements from the middle of an array is possibly the worst use-case for an array data structure, I hope your Prof tells you about that, IF you need preserve the relative ordering of the elements.<br /><br />SotL's suggestion to move or copy the last element over the deleted one is the best method if the order is unimportant.<br /><br />If the order needs to be preserved after deletion you should be using a linked list if this is a common use-case for the data. Other data structures such as a set implemented as a red-black tree are good if insertion and deletion is common and the members must be sorted ascending (or descending) at all times.

PARTNERS