Template Function ADS::pairWithSum

Function Documentation

template<class T, class S>
std::optional<std::pair<std::size_t, std::size_t>> ADS::pairWithSum(const std::vector<T> &A, const S &x)

pairWithSum(): two places i < j of the sorted A with A[ i ] + A[ j ] = x, the sum computed in the type S, or nothing; O( n )

Pre:

A is sorted

Post:

A[ i ] + A[ j ] = x if there is a pair