Skip to content

Commit aed3b36

Browse files
author
Colin Robertson
authored
Update algorithm-functions.md
Simplify example. Update naming and formatting per style.
1 parent 23de610 commit aed3b36

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

docs/standard-library/algorithm-functions.md

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -212,41 +212,30 @@ The template function returns **true** only if, for some `N` in the range
212212
#include <algorithm>
213213
#include <iostream>
214214

215-
// Returns whether element is even
216-
bool is_even(int elem)
217-
{
218-
return elem % 2 == 0;
219-
}
220215

221216
int main()
222217
{
223-
using namespace std;
224-
list <int> L;
225-
list <int>::iterator Iter;
226-
list <int>::iterator result1, result2;
227-
228-
L.push_back(51);
229-
L.push_back(41);
230-
L.push_back(11);
231-
L.push_back(21);
232-
L.push_back(20);
233-
234-
cout << "L = ( ";
235-
for (Iter = L.begin(); Iter != L.end(); Iter++)
236-
cout << *Iter << " ";
237-
cout << ")" << endl;
238-
239-
// Check if there is an even elememt in L.
240-
if (any_of(L.begin(), L.end(), is_even))
241-
cout << "There is even element in L\n";
242-
else
243-
cout << "There are not even elements in L.\n";
218+
using namespace std;
219+
220+
list<int> li { 51, 41, 11, 21, 20 };
221+
222+
cout << "li = ( ";
223+
for (auto const& el : li)
224+
cout << el << " ";
225+
cout << ")" << endl;
226+
227+
// Check if there is an even elememt in li.
228+
auto is_even = [](int const elem){ return !(elem % 2); };
229+
if (any_of(li.begin(), li.end(), is_even))
230+
cout << "There's an even element in li.\n";
231+
else
232+
cout << "There are no even elements in li.\n";
244233
}
245234
```
246235

247236
```Output
248237
L = ( 51 41 11 21 20 )
249-
There is even element in L
238+
There's an even element in li.
250239
```
251240

252241
## <a name="binary_search"></a> binary_search

0 commit comments

Comments
 (0)