Get Time
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Question about max_element and accumulate fuction | Reply
Hi, I am newbe in computer science field.
what is the max_element and accumulate function doing for?

why lo and hi equal to them?

int lo = *max_element( folders.begin(), folders.end() );
int hi = accumulate( folders.begin(), folders.end(), 0 );
Re: Question about max_element and accumulate fuction (response to post by ssuchieh) | Reply
max_element() returns an iterator to the max element in the list (vector, set, or whatever).. So, if you want the value (and not the position the element is), you have to dereference using the * operator.

accumulate() returns the sumation of the elements in the list (vector, set, or whatever) plus an additional that you pass as (third) argument (often you use 0)

I think you don't disturb anyone doing these basic questions but you can save your time searching for your answers here:
If your questions are about C++, you can look at and if you are searching specifically for stl functions:

As I said, you can ask but if you search at google first, you will get your answers sooner.

EDIT: "lo" is the max element because its search space starts there.The way the algorithm author did, he knows that the answer is between "lo" and "hello", ops, "hi" (eheheh). You have to analyze the algorithm and try to understand why the search space is between the max element and the sumation of all elements..