
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Stable Sort in C++ STL
The stable_sort method of STL first sorts the components with name as the key in ascending order and afterward the components are arranged with their segment as the key. Moreover, The stable_sort() calculation is viewed as steady in light of the fact that the overall request of comparable components is kept up. Here is the source code of the C++ program which exhibits the stable_sort() calculation demonstrated as follows;
Example
#include <bits/stdc++.h> using namespace std; int main(){ int arr[] = { 11, 15, 18, 19, 16, 17, 13, 20, 14, 12, 10 }; int n = sizeof(arr) / sizeof(arr[0]); stable_sort(arr, arr + n); cout << "Array after sorting is ="; for (int i = 0; i < n; ++i) cout << arr[i] << " "; return 0; }
Output
This C++ program yields the following array to be sorted in ascending order as follows;
Array after sorting is= 10 11 12 13 14 15 16 17 18 19 20
Advertisements