Sort given array to descending | C ++ program to implement the above approach ; Function to sort first K array elements in descending and last N - K in ascending order ; Sort the array in descending order ; Sort last ( N - K ) array elements in ascending order ; Print array elements ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void sortArrayInDescAsc ( int arr [ ] , int N , int K ) { sort ( arr , arr + N , greater < int > ( ) ) ; sort ( arr + K , arr + N ) ; for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 7 , 6 , 8 , 9 , 0 , 1 , 2 , 2 , 1 , 8 , 9 , 6 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 6 ; sortArrayInDescAsc ( arr , N , K ) ; }