Skip to content

Instantly share code, notes, and snippets.

@danielgospodinow
Last active September 22, 2019 19:46
Show Gist options
  • Save danielgospodinow/915d259161b6c277c6964605da2bdd21 to your computer and use it in GitHub Desktop.
Save danielgospodinow/915d259161b6c277c6964605da2bdd21 to your computer and use it in GitHub Desktop.
Array List remove operation
/**
* Remove all elements from the data structure which match
* the item provided.
*
* @tparam T type
* @param item item to be removed
*/
template<typename T>
void ArrayList<T>::remove(const T &item) {
// Iterate through all elements and remove those
// who are equal to the one provided.
for (int i = 0; i < _size; ++i) {
if (_array[i] == item) {
removeAt(i);
// Reduce the iterator variable in order
// to stay at the same place after an element
// remove operation.
--i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment