Last active
September 22, 2019 19:46
-
-
Save danielgospodinow/915d259161b6c277c6964605da2bdd21 to your computer and use it in GitHub Desktop.
Array List remove operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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