Last active
September 22, 2019 19:51
-
-
Save danielgospodinow/0fe3dee5a7f96b25106958cac07cf401 to your computer and use it in GitHub Desktop.
Array List get 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
/** | |
* Finds and returns an element by its index. | |
* | |
* @tparam T type | |
* @param index index of the required element. | |
* @return the element required | |
*/ | |
template<typename T> | |
T ArrayList<T>::get(const int index) const { | |
if (index < 0 || index >= _size) { | |
// If the index is out of bounds, throw an exception. | |
throw std::invalid_argument("Index out of bounds"); | |
} else { | |
// Retrieve the element from the specified index. | |
return _array[index]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment