xxxxxxxxxx
//* C++ STL sort() will sort your's unsorted program sort
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
string s;
cin >> s; //! Input: Subodh
sort(s.begin(), s.end());
cout << s << endl;
//! Array sorting usign STL
// sort an array in ascending order
char c[] = {0, 30, 40, 88, 99, 22, 77, 56, 120, 66};
int n = sizeof(c) / sizeof(c[0]);
sort(c, c + n);
cout << c;
//* Ranged based for loop
for (int i : c)
{
cout << i << " ";
}
cout << "\n";
// sort an array in descending order
reverse(c, c + n);
for (int i : c)
cout << i << " ";
cout << "\n";
// sort an array in descending order
sort(c, c + n, greater<int>());
for (int i : c)
cout << i << " ";
return 0;
}
xxxxxxxxxx
// STL IN C++ FOR SORING
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
int n = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+n); // ASCENDING SORT
reverse(arr,arr+n); //REVERESE ARRAY
sort(arr, arr + n, greater<int>());// DESCENDING SORT
}
xxxxxxxxxx
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = { 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
int n = sizeof(arr) / sizeof(arr[0]);
/*Here we take two parameters, the beginning of the
array and the length n upto which we want the array to
be sorted*/
sort(arr, arr + n);
cout << "\nArray after sorting using "
"default sort is : \n";
for (int i = 0; i < n; ++i)
cout << arr[i] << " ";
return 0;
}