

function numericSort(x,y) {
    var a = new Number(x) ;
    var b = new Number(y) ;
    return (a - b) ;
}

function MedianProblem(x) {
    this.data = new List() ;
    this.medianValue = new String() ;
    this.count = new Number() ;

    if ((x == undefined) || (x == null) ) {
        x = "" ;
    }
    (this.data).assign(x) ;
}

MedianProblem.prototype.assign = function (x) {
    (this.data).assign(x) ;
}

MedianProblem.prototype.evaluate = function() {
    var length = new Number() ;
    var middex = new Number() ;
    var value  = new Number() ;
    
    length = (this.data.listArray).length ;
    (this.data).sort(numericSort)
       
    if ((length % 2) > 0) {
        middex = length/2 - 0.5 ;
        value = (this.data).item(middex) ;

    } else {
        middex = length/2 ;
        value = parseInt((this.data).item(middex-1)) + parseInt((this.data).item(middex)) ;
        value = value/2 ;    
    }
    this.medianValue = value ;
    
    return value ;
}


MedianProblem.prototype.median = function() {
    return this.medianValue ;
}

