Sort first k values in ascending order and remaining n | C # program to sort first k elements in increasing order and remaining n - k elements in decreasing ; function to sort the array ; Sort first k elements in ascending order ; Sort remaining n - k elements in descending order ; Driver code ; Our arr contains 8 elements
using System ; public class SortExample { static void printOrder ( int [ ] arr , int k ) { int n = arr . Length ; Array . Sort ( arr , 0 , k ) ; Array . Sort ( arr , k , n - k ) ; Array . Reverse ( arr , k , n - k ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , - 1 } ; int k = 4 ; printOrder ( arr , k ) ; Console . Write ( " { 0 } " , String . Join ( " ▁ " , arr ) ) ; } }