-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18.6 ListSort.cpp
More file actions
39 lines (30 loc) · 836 Bytes
/
18.6 ListSort.cpp
File metadata and controls
39 lines (30 loc) · 836 Bytes
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
#include <list>
#include <iostream>
using namespace std;
bool SortPredicate_Descending (const int& lsh, const int& rsh)
{
// define criteria for list::sort: return true for desired order
return (lsh > rsh);
}
template <typename T>
void DisplayContents (const T& container)
{
for (auto element = container.cbegin();
element != container.cend();
++ element )
cout << *element << ' ';
cout << endl;
}
int main ()
{
list <int> linkInts{ 0, -1, 2011, 444, -5 };
cout << "Initial contents of the list are - " << endl;
DisplayContents (linkInts);
linkInts.sort ();
cout << "Order after sort():" << endl;
DisplayContents (linkInts);
linkInts.sort (SortPredicate_Descending);
cout << "Order after sort() with a predicate:" << endl;
DisplayContents (linkInts);
return 0;
}