// STL IN C++ FOR SORING#include<bits/stdc++.h>#include<iostream>usingnamespace std;intmain(){int arr[]={1,5,8,9,6,7,3,4,2,0};int n =sizeof(arr)/sizeof(arr[0]);sort(arr, arr+n);// ASCENDING SORTreverse(arr,arr+n);//REVERESE ARRAY sort(arr, arr + n,greater<int>());// DESCENDING SORT}
#include<algorithm>#include<functional>#include<array>#include<iostream>#include<string_view>intmain(){
std::array<int,10> s ={5,7,4,2,8,6,1,9,0,3};auto print =[&s](std::string_view const rem){for(auto a : s){
std::cout << a <<' ';}
std::cout <<": "<< rem << '
';};
std::sort(s.begin(), s.end());print("sorted with the default operator<");
std::sort(s.begin(), s.end(), std::greater<int>());print("sorted with the standard library compare function object");struct{booloperator()(int a,int b)const{return a < b;}} customLess;
std::sort(s.begin(), s.end(), customLess);print("sorted with a custom function object");
std::sort(s.begin(), s.end(),[](int a,int b){return a > b;});print("sorted with a lambda expression");}// Output://0 1 2 3 4 5 6 7 8 9 : sorted with the default operator<//9 8 7 6 5 4 3 2 1 0 : sorted with the standard library compare function object//0 1 2 3 4 5 6 7 8 9 : sorted with a custom function object//9 8 7 6 5 4 3 2 1 0 : sorted with a lambda expression
#include<bits/stdc++.h>usingnamespace std;intmain(){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 << "
Array after sorting using "
"default sort is :
";for(int i =0; i < n;++i)
cout << arr[i]<<" ";return0;}