how to reverse sort an array in c++ code example
Example 1: how to sort in descending order c++
int arr[10];
int length = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+length, greater<int>());
Example 2: reverse sort cpp
int main(){
int arr[5] = {1,3,2,4,5};
sort(arr, arr+5, greater<int>());
return 0;
}
Example 3: how to sort in descending order in c++
sort(str.begin(), str.end(), greater<int>());
cout<<str;
Example 4: c++ reverse array
int arr[5] = {1, 2, 3, 4, 5};
for(int i = 0; i < size(arr); i++) {
int temp = arr[i];
arr[i] = arr[size(arr) - 1 - i];
arr[size(arr) - 1 - i] = temp;
}