cpp implementation of Search For a Range