how to sort in descending order c++
int arr[10];
int length = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+length, greater<int>());
how to sort in descending order c++
int arr[10];
int length = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+length, greater<int>());
how to sort an array in c++
#include <bits/stdc++.h>
using namespace std;
#define size(arr) sizeof(arr)/sizeof(arr[0]);
int main(){
int a[5] = {5, 2, 6,3 ,5};
int n = size(a);
sort((a), a + n);
for(int i = 0; i < n; i++){
cout << a[i];
}
return 0;
}
array sort c++
#include <iostream>
2 #include <array>
3 #include <string>
4 #include <algorithm>
5
6 using namespace std;
7
8 int main(){
9 array<string, 4> colours = {"blue", "black", "red", "green"};
10 for (string colour : colours){
11 cout << colour << ' ';
12 }
13 cout << endl;
14 sort(colours.begin(), colours.end());
15 for (string colour : colours){
16 cout << colour << ' ';
17 }
18 return 0;
19 }
66
20
21 /*
22 Output:
23 blue black red green
24 black blue green red
25 */
sort in descending order c++
sort(arr, arr + n, greater<int>());
stl sort in c++
sort(arr, arr+n, greater<int>()); // sorts in descending order
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us