VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdstable_partition-in-c/

⇱ std::stable_partition in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::stable_partition in C++

Last Updated : 23 Oct, 2025

stable_partition() rearranges elements in a container so that those satisfying a given condition come first, while preserving their original order.

  • It’s called stable because it keeps the relative order of elements the same within each group.
  • It divides elements in a container (like an array or vector) into two groups based on a given condition .
  • The syntax of std::stable_sort is std::stable_sort(first, last, comp), where first and last specify the range of elements to be sorted, and comp is an optional comparison function that determines the sorting order.
  • It is present in <algorithm> header file.

Output
6 9 1 2 7 5 8 0 0 

Output:

odd numbers: 1 3 5 7 9
even numbers: 2 4 6 8
Comment
Article Tags: