[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppSort
Manual ways of sorting:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppSort
(C++) std::sort
STL algorithm for sorting. Can be found in the header file <algorithm>.Manual ways of sorting:
struct SortOnSecondLetter { bool operator()(const std::string& lhs, const std::string& rhs) { return (lhs.substr(1,2) < rhs.substr(1,2)); } }; struct Couter { void operator()(const std::string& s) { std::cout << s << std::endl; } }; int main() { std::vector<std::string> v; v.push_back("acb"); v.push_back("cbc"); v.push_back("bac"); v.push_back("baa"); std::cout << "Before sort: " << std::endl; std::for_each(v.begin(), v.end(), Couter()); std::sort(v.begin(),v.end(),SortOnSecondLetter()); std::cout << "After sort: " << std::endl; std::for_each(v.begin(), v.end(), Couter()); }
- include <iostream>
- include <vector>
- include <string>
- include <algorithm>
'Sort' links
Code links
- algorithm (header file)
- bool
- cout
- endl
- for_each
- int
- iostream (header file)
- main
- operator
- std
- std::cout
- std::endl
- std::for_each
- std::string
- std::vector
- string
- string (header file)
- struct
- vector
- vector (header file)
- void
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
