Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
The <algorithm> header contains a huge collection of functions for searching, sorting, and manipulating data efficiently.
sort()Sorts elements in a range in O(N log N).
binary_search()Checks if element exists in a sorted range.
reverse()Reverses the order of elements.
max_element()Finds the largest element in a range.
next_permutation()Generates lexicographical permutations.
vector<int> v = {40, 10, 30, 20};
sort(v.begin(), v.end());
// To sort in descending order:
sort(v.begin(), v.end(), greater<int>());Knowing STL algorithms is a massive advantage in CP. They are faster to write and often more optimized than manual implementations.