Unfortunately that's not terribly clear, as he has "several jagged
arrays". If he had a single jagged array, then the meaning of "each
array" would be clear. As it is, he could mean each "subcomponent"
array or he could mean each "top-level" jagged array.
Comically I had the same confusion but not until I'd written the
following. Figured I'd post anyway.
using System;
using System.Collections;
namespace ConsoleApplication3
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,2,4,7,9,11})); //5.5
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,2,10,9,11})); //10
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,8,10,9,11,15,15})); //9
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,4,10,12,33,88})); //11
Console.WriteLine("Median = {0}",GetMedian(new ArrayList(new int[]
{1,2,3,100}))); //2.5
Console.ReadLine();
}
static double GetMedian(int[] pNumbers)
{
int size = pNumbers.Length;
int mid = size /2;
double median = (size % 2 != 0) ? (double)pNumbers[mid] :
((double)pNumbers[mid] + (double)pNumbers[mid-1]) / 2;
return median;
}
static double GetMedian(ArrayList pNumbers)
{
return GetMedian((int[])pNumbers.ToArray(typeof(int)));
}
}
}