Skip to content

Commit

Permalink
Added smuos#2 median() function
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwentao committed Oct 1, 2014
1 parent 0ea92be commit 376816f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ float mean (int num[], int length)



//Add median function
float median (int num[], int length)
{
int medianNum = length / 2;
//Determine the size of array is even or odd
if (length % 2 == 0)
{
medianNum = (num[medianNum - 1] + num[medianNum]) / 2;
return medianNum;
} else
return medianNum;
}



// Comparison function for qsort()
int numcmp (const void *a, const void *b) {
int x = *((int*) a);
Expand Down

0 comments on commit 376816f

Please sign in to comment.