It all works (ie sorts & averages correctly) - but where on earth has the number 6 in the sorted numbers come from?
Check out the sorting routine because it doesn't work. The first number should be 25, while the last number should be 34 not 33.

Also your average is not correct, since 27 + 30 / 2 = 28.5 (28 as integer) not 31

Very likely the error comes from the wrong sorting.

Cheers

Al.