Rearrange all elements of array which are multiples of x in increasing order | C # implementation of the approach ; Function to sort all the multiples of x from the array in ascending order ; Insert all multiples of 5 to a vector ; Sort the vector ; update the array elements ; Driver code ; Print the result
using System ; using System . Collections . Generic ; class GFG { static void sortMultiples ( int [ ] arr , int n , int x ) { List < int > v = new List < int > ( ) ; int i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] % x == 0 ) v . Add ( arr [ i ] ) ; v . Sort ( ) ; int j = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % x == 0 ) arr [ i ] = v [ j ++ ] ; } } public static void Main ( ) { int [ ] arr = { 125 , 3 , 15 , 6 , 100 , 5 } ; int x = 5 ; int n = arr . Length ; sortMultiples ( arr , n , x ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } }