c++ methods for sorted data