text: Change in Median of given array after deleting given elements | C # program for the above approach ; Function to find the median change after removing elements from arr2 [ ] ; To store the median ; If N is odd ; If N is even ; Find the current element in arr1 ; Erase the element ; Decrement N ; If N is odd ; If N is even ; Print the corresponding difference of median ; Driver Code ; Given arrays ; Function Call
code: using System ; using System . Collections . Generic ; class GFG { static void medianChange ( List < int > arr1 , List < int > arr2 ) { int N = arr1 . Count ; List < double > median = new List < double > ( ) ; if ( ( N & 1 ) != 0 ) { median . Add ( arr1 [ N / 2 ] * 1.0 ) ; } else { median . Add ( ( arr1 [ N / 2 ] + arr1 [ ( N - 1 ) / 2 ] ) / 2.0 ) ; } foreach ( int x in arr2 ) { int it = arr1 . IndexOf ( x ) ; arr1 . RemoveAt ( it ) ; N -- ; if ( ( N & 1 ) != 0 ) { median . Add ( arr1 [ N / 2 ] * 1.0 ) ; } else { median . Add ( ( arr1 [ N / 2 ] + arr1 [ ( N - 1 ) / 2 ] ) / 2.0 ) ; } } for ( int i = 0 ; i < median . Count - 1 ; i ++ ) { Console . Write ( median [ i + 1 ] - median [ i ] + " ▁ " ) ; } } static void Main ( ) { List < int > arr1 = new List < int > ( new int [ ] { 2 , 4 , 6 , 8 , 10 } ) ; List < int > arr2 = new List < int > ( new int [ ] { 4 , 6 } ) ; medianChange ( arr1 , arr2 ) ; } }