Skip to the content of the web site.

Project W.6: Find and find all

The find function returns the index at which the sought after value is found and returns the capacity of the array if the value is not found. The find all function returns an array that stores all indices of the sought after value and returns a dynamically allocated array containing all of the indices. The last entry of this dynamically allocated array will be the capacity of the array, so if no instances of the sought value are found, an array of capacity one will be returned and the value of that entry will be the capacity of the passed array.

Integer implementation

std::size_t      find( int array[], std::size_t capacity, int sought_value );
std::size_t *find_all( int array[], std::size_t capacity, int sought_value );

Templated implementation

template <typename T>
std::size_t      find( T array[], std::size_t capacity, T sought_value );

template <typename T>
std::size_t *find_all( T array[], std::size_t capacity, T sought_value );