We can sort the elements of the collection we have in array or vector, as well as find specific content of the element. For these purposes, we have to use the algorithm feature provided by the C++ Standard Library. Let's take a look at the following code to demonstrate the sorting element capability in the algorithm feature:
/* sort.cpp */ #include <vector> #include <algorithm> #include <iostream> bool comparer(int a, int b) { return (a > b); } auto main() -> int { std::cout << "[sort.cpp]" << std::endl; // Initializing a vector containing several integer elements std::vector<int> vect = { 20, 43, 11, 78, 5, 96 }; // Displaying the original elements of the vector std::cout << "Original Data : "; for (auto v : vect) std::cout ...