AlgoMaster Logo

Sorting Algorithms (sort, stable_sort, partial_sort)

Last Updated: May 22, 2026

High Priority
10 min read

The STL's sorting family covers four jobs: sort the whole range, sort while preserving the order of equal elements, sort only the first k smallest, and partition around the element that belongs at position n. Each one has different complexity guarantees and different trade-offs, and the right pick depends on what is needed from the result. This chapter walks through std::sort, std::stable_sort, std::partial_sort, and std::nth_element, plus the comparator rules they all share.

Premium Content

Subscribe to unlock full access to this content and more premium articles.