begum wrote:
in this program they want me to find the max value of a subsequence in
a given sequnce of numbers(the sequence is represented by an array) by
using templates and pointers.also i must write a main in order to
instantiate differnt objects of my class. in this program i don't want
to find the sum!!!!. please can anyone help me?
The header <algorithmprovides a generic function:
template<class RandomAccessIterator>
void nth_element(RandomAccessIterator first,
RandomAccessIterator nth,
RandomAccessIterator last);
using std::less, but you can also supply a comparison predicate of your own:
template<class RandomAccessIterator, class Compare>
void nth_element(RandomAccessIterator first,
RandomAccessIterator nth,
RandomAccessIterator last,
Compare comp);
So, in order to find the minimum in a range [from,to), you would do:
nth_element( from, from, to );
minimum = *from;
You can vary this to find the maximum instead.
Warning: this algorithm rearranges the sequence. Make sure that you are
allowed to do that.
Best
Kai-Uwe Bux