Created
December 16, 2011 13:52
-
-
Save dazfuller/1486123 to your computer and use it in GitHub Desktop.
Ignoring the Voices: C++11 Example - Basic Sorting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void PrintList(const vector<int>& list) | |
{ | |
for (auto i : list) | |
{ | |
cout << i << " "; | |
} | |
cout << endl; | |
} | |
bool SortAscending(const int x, const int y) | |
{ | |
return x < y; | |
} | |
bool SortDescending(const int x, const int y) | |
{ | |
return x > y; | |
} | |
int main(int argc, char** argv) | |
{ | |
vector<int> myList = { 4, 1, 6, 2, 13 }; | |
PrintList(myList); | |
sort(myList.begin(), myList.end(), SortAscending); | |
PrintList(myList); | |
sort(myList.begin(), myList.end(), SortDescending); | |
PrintList(myList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled as follows with GCC 4.6.1 on Ubuntu 11.10
g++ -Wall -Werror -std=c++0x -o basic_sort basic_sort.cpp