This function returns median of ar1 [ ] and ar2 [ ] . Assumptions in this function : Both ar1 [ ] and ar2 [ ] are sorted arrays Both have n elements
static int getMedian ( int [ ] a , int [ ] b , int startA , int startB , int endA , int endB ) { if ( endA - startA == 1 ) { return ( Math . Max ( a [ startA ] , b [ startB ] ) + Math . Min ( a [ endA ] , b [ endB ] ) ) / 2 ; }