AlgoMaster Logo

Sorting Algorithms (sort, stable_sort, partial_sort)

Last Updated: May 17, 2026

10 min read

The STL's sorting family covers four jobs: sort the whole thing, sort it 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 you actually need 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.