Sort array using inbuilt sort function in decreasing order 1

Sort array using inbuilt sort function in decreasing order

// Sort(In Ascending Order) Array using Inbuilt Sort function
sort(arr, arr+n);
  
// Sort(In Ascending Order) Vector using Inbuilt Sort function
sort(arr.begin(), arr.end());

// Sort(In Descending Order) Array using Inbuilt Sort function
sort(arr, arr+n, greater())
  
// Sort(In Descending Order) Vector using Inbuilt Sort function
sort(arr.begin(), arr.end(), greater())

Here is what the above code is Doing:
1. sort(arr, arr+n) – This is sorting the array arr in ascending order.
2. sort(arr, arr+n, greater()) – This is sorting the array arr in descending order.
3. sort(arr.begin(), arr.end()) – This is sorting the vector arr in ascending order.
4. sort(arr.begin(), arr.end(), greater()) – This is sorting the vector arr in descending order.

Similar Posts