
Answer:
//Given variables,
int [ ] x = array of integer elements
int n = x.length       // number of elements in array x
int m      //not set yet
//Custom variable(s)
int [ ] sortedx = sorted form of array x
double medianpos = hold the median position
//Find if n is odd or even
if (n % 2 == 0){ Â Â Â Â Â Â //if the modulus of n by 2 gives zero(0)
n is even Â
medianpos = n/2
m = (sortedx [medianpos -1] + sortedx [medianpos] ) / 2
}
else{
n is odd
medianpos = Â (n+1) / 2 Â Â Â Â Â // add 1 to n and divide the result by 2
m = sortedx [medianpos - 1] Â Â Â // since arrays are indexed from zero(0)
}
Explanation:
Explanations are written as comments in the answer.
Hope it helps!