Results 1 to 3 of 3

Thread: max_element () in C++

  1. #1
    ScottWright is offline Senior Member
    Join Date
    Dec 2009
    Posts
    243
    Rep Power
    3

    Default max_element () in C++

    Hi I am last year MCA student, currently I am learning C++ programming language.I want to know about max_element () function in C++. So please tell me how to use the max_element () function in the C++. All possible replies and suggestions on this topic are very much appreciated.

  2. #2
    AdamsClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    247
    Rep Power
    3

    Default

    This function used to return iterator that shows element with max value in specific range. Max_element () function work shown as below:

    Code:
    template <class FrwrdItrtr>
      	FrwrdItrtr max_element ( FrwrdItrtr fst, FrwrdItrtr lst )
    {
      		FrwrdItrtr lrgst = fst;
      		if (fst==lst) return lst;
      		while (++fst!=lst)
        		if (*lrgst<*fst)    
          		lrgst=fst;
      		return lrgst;
    }

  3. #3
    TorresScott is offline Senior Member
    Join Date
    Dec 2009
    Posts
    239
    Rep Power
    3

    Default

    syntax of max_element() function:

    Code:
    template <class FrwrdItrtr>
      		FrwrdItrtr max_element ( FrwrdItrtr fst, FrwrdItrtr lst );
    template <class FrwrdItrtr, class Cmpr>
     		 FrwrdItrtr max_element ( FrwrdItrtr fst, FrwrdItrtr lst, 
                                    Compare cmp );

Similar Threads

  1. max_element() in C++
    By ashley_black in forum Programming
    Replies: 1
    Last Post: 04-15-2010, 12:24 PM
  2. Using max_element () in C++
    By EvansMitchell in forum Programming
    Replies: 2
    Last Post: 03-08-2010, 02:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48