Pages

Thursday, December 30, 2010

Grouping Algorithm Using Javascript

/**
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 29,2010
 * @version : 1.0
 *
 * This function will provide distinct selection algorithm.
 */

/**
 * Constructor service
 * @param data array of data
 */
function GroupingAlgorithm(data){
    this.data = data;
}

/**
 * a mehtod that provide base service to slice the data.
 * var data = [1,2,2,3,1,2]
 *          = [2,2,3,2]
 *          = [3]
 *          = []
 * @param varData array of data
 * @return sliced array
 */
GroupingAlgorithm.prototype.first = function(varData){
    var value = varData[0];
    var newData = new Array();
    var k = 0;
    for(i=1;i<varData.length;i++){
        if(varData[i]!=value){
            newData[k]=varData[i];
            k++;
        }
    }
    return newData;
};


/**
 * This function will do like what happend at SELECT DISTINCT 
 * in MySQL.
 * @return array unsorted distinct value;
 */
GroupingAlgorithm.prototype.getDistinctValue = function(){
    var rest = true;
    var distinctValue = new Array();
    var d = 0;
    var copyData = this.data;
    while(rest){
        distinctValue[d]=copyData[0];
        copyData = this.first(copyData);
        d++;
        if(copyData.length==0){
            rest = false;
        }

    }
    return distinctValue;
};

/**
 * A method to know how many occurence for specified value
 *
 * @return array of data
 */
GroupingAlgorithm.prototype.getTotalNumber = function(){
    var distinctData = this.getDistinctValue();
    var nTimes = new Array();
  
    for(i=0;i<distinctData.length;i++){
        var n = 0;
        for(j=0;j<this.data.length;j++){
            if(distinctData[i]==this.data[j]){
                n++;
            }
        }
        nTimes[i]=n;
    }
    return nTimes;
};
        

Selection Algorithm Using Java

/**
 * Selection Algorithm
 * This function provide service for selection algorithm.
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 29, 2010
 * @version : 1.0
 */

/**
 * Constructor service
 * @param data array of data
 */
function DataAlgorithm(data){
    this.data = data;
}

/**
 * function to get min value from the data
 * @return min value of the data
 */
DataAlgorithm.prototype.getMinValue = function(){
    return this.data[this.getMinValueIndex()];
};

/**
 * function to get max value from the data
 * @return max value of the data
 */
DataAlgorithm.prototype.getMaxValue = function(){
    return this.data[this.getMaxValueIndex()];
};

/**
 * function to get index of the min value
 * @return number index of the min value
 */
DataAlgorithm.prototype.getMinValueIndex = function(){
    var minIndex = this.data[0];
    for(i=0;i<this.data.length;i++){
        if(this.data[i+1]<this.data[minIndex]){
            minIndex = i+1;
        }
    }
    return minIndex;
};

/**
 * method to get index of the max value
 * @return number index of the max value
 */
DataAlgorithm.prototype.getMaxValueIndex = function(){
    var maxIndex = this.data[0];
    for(i=0;i<this.data.length;i++){
        if(this.data[i+1]>this.data[maxIndex]){
            maxIndex = i+1;
        }
    }
    return maxIndex;
};
      

Selection Algorithm In Python

# Selection Algorithm
#
# @author  : irfanudin ridho
# @email   : irfan.ub@gmail.com
# @date    : December 31, 2010
# @version : 1.0


class SA:

    def __init__(self,data):
        self.data = data
 
    def getMinIndex(self):
        minIndex = 0
        lenn = len(self.data)
        for i in range(lenn):
            if(self.data[i]<self.data[minIndex]):
                minIndex = i
        return minIndex
 
    def getMinValue(self):
        return self.data[self.getMinIndex()]

    def getMaxIndex(self):
        maxIndex = 0
        lenn = len(data)
        for i in range(lenn):
            if(self.data[i]>self.data[maxIndex]):
                maxIndex = i
        return maxIndex

    def getMaxValue(self):
        return self.data[self.getMaxIndex()]
 

List In Javascript

/**
 * A List of ADT. This ADT works well like list in other library.
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 31, 2010
 * @version : 1.0
 */

/**
 * Constructor service
 */
function List(){
    this.data = new Array();
}

/**
 * method to add an element to list
 *
 * @param item string,number,boolean value. element to be added
 */
List.prototype.add = function(item){
    var len = this.data.length;
    this.data[len] = item;
};

/**
 * method to remove an element from the list
 *
 * @param item string, number or boolean as what the list contains.
 */
List.prototype.remove = function(item){
    var newData = new Array();
    var len = this.data.length;
    var k = 0;
    for(i=0;i<len;i++){
        if(this.data[i]!=item){
            newData[k] = this.data[i];
            k++;
        }
    }
    this.data = newData;
};


/**
 * method to know how many elements in the list
 *
 * @return number number of elements
 */
List.prototype.size = function(){
    return this.data.length;
};

/**
 * method to give this list as an array
 *
 * @return an array
 */
List.prototype.toArray = function(){
    return this.data;
};
      

Queue In Javascript

/**
 * A Queue ADT. This ADT provide functionality for FIFO 
 * data structure.
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 31, 2010
 * @version : 1.0
 */

/**
 * A constructor service.
 */
function Queue(){
    this.data = new Array();
}

/**
 * method to insert an element to the Queue
 *
 * @param item string, number, boolean element to be inserted.
 */
Queue.prototype.push = function(item){
    var len = this.data.length;
    var newData = new Array();
    newData[0] = item;
    for(i=0;i<len;i++){
        newData[i+1]=this.data[i];
    }
    this.data = newData;
};

/**
 * A method to remove the first item inserted.
 *
 * @return first element of the Queue.
 */
Queue.prototype.pop = function(){
    var len = this.data.length;
    var first = this.data[len-1];
    var newData = new Array();
    for(i=1;i<len;i++){
        newData[i-1]=this.data[i];
    }
    this.data = newData;
    return first;
};

/**
 * A method to get how many elements in the Queue
 *
 * @return number number of elements.
 */
Queue.prototype.size = function(){
    return this.data.length;
};

/**
 * A method to represent this queue as an array data structure.
 *
 * @return array of data
 */
Queue.prototype.toArray = function(){
    return this.data;
}

Stack In Javascript

/**
 * An ADT of Stack. This is an implementation of LIFO 
 * data structure.
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 31, 2010
 * @version : 1.0
 */

/**
 * A constructor service.
 */
function Stack(){
    this.data = new Array();
}

/**
 * A method to insert an element to the top position.
 *
 * @param item string, number or boolean value to be inserted
 */
Stack.prototype.push = function(item){
    var len = this.data.length;
    this.data[len]=item;
};

/**
 * A method to get the top position from the stack. As well as
 * to remove it.
 *
 * @return the value of the top position.
 */
Stack.prototype.pop = function(){
    var len = this.data.length;
    var last = this.data[len-1];
    var newStack = new Array();
    for(i=0;i<len-1;i++){
        newStack[i]=this.data[i];
    }
    this.data = newStack;
    return last;
};

/**
 * A method to get the size of elements in the Stack.
 *
 * @return number number of elements in Stack
 */
Stack.prototype.size = function(){
     return this.data.length;
};

/**
 * A method to convert the stack to be an array representation.
 *
 * @return an array of data.
 */
Stack.prototype.toArray = function(){
     return this.data;
}
         

Map In Javascript

/**
 * An ADT of Map. This ADT will do functionality as 
 * the key value ADT.
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 31, 2010
 * @version : 1.0
 */

/**
 * A constructor service.
 */
function Map(){
    this.key = new Array();
    this.value = new Array();
}

/**
 * A method to add an elements to the Map
 *
 * @param k string, number key element
 * @param v string, number, boolean value element
 */
Map.prototype.add = function(k,v){
    var len = this.key.length;
    this.key[len] = k;
    this.value[len] = v;
};

/**
 * A method to get an element as suitable for the key
 *
 * @param k key of the element
 * @return value as suitable for the key.
 */
Map.prototype.get = function(k){
    var index = 0;
    for(i=0;i<k.length;i++){
        if(this.key[i]==k)
        index = i;
    }
    return this.value[index];
};
     

Manipulating Array

/**
 * This class provide functionality to manipulate array of 2
 * dimension
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 31, 2010
 * @version : 1.0
 */

/**
 * A constructor service.
 */
function Arr(){

}

/**
 * A method to create a two dimensional array based on two array.
 * The format of the array is [n][2]. The first element is placed in
 * [n][0], while the second element is placed in [n][1]
 *
 * @param f array the first array
 * @param s array the second array
 * @return two dimensional of array
 */
Arr.prototype.twoDim = function(f,s){
    if(f.length!=s.length)
        return 'must same in length';
    var twoDimm = new Array();
    for(i=0;i<f.length;i++){
        twoDimm[i] = new Array();
        twoDimm[i][0] = f[i];
        twoDimm[i][1] = s[i];
    }
    return twoDimm;
};

/**
 * A method to get the first value of the second index
 * operator [n][0]
 *
 * @param data two dimensional of array in format [n][2]
 * @return first one dimensional of array in format[n]
 */
Arr.prototype.getFirst = function(data){
    var first = new Array();
    for(i=0;i<data.length;i++){
        first[i] = data[i][0];
    }
    return first;
};

/**
 * A method to get the second value of the second index 
 * operator [n][1]
 *
 * @param data two dimensional of array in format [n][2]
 * @return second one dimensional of array in format[n]
 */
Arr.prototype.getSecond = function(data){
    var second = new Array();
    for(i=0;i<data.length;i++){
        second[i] = data[i][1];
    }
    return second;
};

Grouping Algorithm

/**
 * Grouping Algorithm
 * This algorithm will do select just a distinct value of the data.
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 31, 2010
 * @version : 2.0
 */

/**
 * A constructor service.
 *
 * @param data array of data.
 */
function Grouping(data){
    this.data = data;
}

/**
 * A private method that provide slice functionality of the 
 * array of data
 *
 * @param data data to be sliced.
 * @return sliced of array
 */
Grouping.prototype.slice = function(data){
    var value = data[0];
    var newData = new Array();
    var k = 0;
    for(i=1;i<data.length;i++){
        if(data[i]!=value){
            newData[k]=data[i];
            k++;
        }
    }
    return newData;
};

/**
 * A method that gives what this class intended. 
 * This gives a distinct
 * value of array in the form of array.
 *
 * @return distinct value of array
 */
Grouping.prototype.create = function(){
    var dataValue = new Array();
    var k = 0;
    var loop = true;
    var data = this.data;
    while(loop){
        dataValue[k] = data[0];
        data = this.slice(data);
        k++;
        if(data.length==0)
            loop = false;
        }
        return dataValue;
};


/**
 * This method provide serive on how many a value counting in the data.
 *
 * @return array counting value.
 */
Grouping.prototype.valueCounting = function(){
    var groupedData = this.create();
    var countValue = new Array();
    var data = this.data;
    for(i=0;i<groupedData.length;i++){
        var k = 1;
        for(j=0;j<data.length;j++){
            if(groupedData[i]==data[j]){
                countValue[i]=k;
                k++;
            }
        }
    }
    return countValue;
};


/**
 * A method to map distinct value and how many occurence of 
 * the value
 * in the data
 *
 * @return two dimensional array in the form [n][2]
 */
Grouping.prototype.mapping = function(){
    var data = this.data;
    var dimData = new Array();
    var value = this.create();
    var countValue = this.valueCounting();
    var len = value.length;
    for(i=0;i<len;i++){
        dimData[i] = new Array();
        dimData[i][0] = value[i];
        dimData[i][1] = countValue[i];
    }
    return dimData;
};

Tuesday, December 28, 2010

Rotating Algorithm Using JS

/**
 * This function will do rotate element of the data.
 * If the step of rotate, n, is equal length of data-1, the data
 * will be reversed.
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 29, 2010
 * @version : 1.0
 */

/**
 * @param data array of data
 * @param n number step to rotate
 * @return datas new rotated data in n step
 */
function Rotate(data,n){
    var datas = new Array();
    for(i=n;i<data.length;i++){
       datas[i] = data[i-n];
    }
    for(i=0;i<n;i++){
        datas[i]= data[data.length-1-i];
    }
    return datas;
}

Monday, December 27, 2010

Simple Substitution Cipher

/**
 * Function that provide substitution encryption and decryption
 * algorithm.
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 28, 2010
 * @version : 1.0
 */


/**
 * @param string text either plaintext or encrypted text
 * /
function SubstitutionCipher(text){
    this.text = text;
}


/**
 * @return encrypted string
 */
SubstitutionCipher.prototype.encrypt = function(){

    var encrypted = this.text.replace(/a/g,'1');
    encrypted = encrypted.replace(/e/g,'2');
    encrypted = encrypted.replace(/i/g,'3');
    encrypted = encrypted.replace(/o/g,'4');
    encrypted = encrypted.replace(/u/g,'5');
    encrypted = encrypted.replace(/ /g,'6');

    return encrypted;
};


/**
 * @return plaintext 
 */
SubstitutionCipher.prototype.decrypt = function(){

    var decrypted = this.text.replace(/1/g,'a');
    decrypted = decrypted.replace(/2/g,'e');
    decrypted = decrypted.replace(/3/g,'i');
    decrypted = decrypted.replace(/4/g,'o');
    decrypted = decrypted.replace(/5/g,'u');
    decrypted = decrypted.replace(/6/g,' ');

    return decrypted;
};
      

Polinomial Differentiation Using JS

/**
 * This function will do polinomial differentioation.
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 28, 2010
 * @version : 1.0
 */




function Polinomial(){
    var x = new Array();
    x[0] = 1;
    var dx = 0.1;
    var y = new Array();
    var fx = 2*x[0];
    y[0] = 1;
    for(i=1;i<12;i++){
        x[i] = x[i-1]+dx;                   //1.1 - 1.2 - 1.3
        y[i]=y[i-1]+dx-fx;
       fx = 2*x[i];
    }
}
                           

Linear Eq Using Numerical Method

/**
 * Function for solving linear equation using numerical method. 
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 28, 2010
 * @version : 1.0
 */


/**
 * @return x number value expected
 */
function getByNumericalMethod(){
    var x=100;
    for(i=0;i<110;i++){
        var y = x-10;
        if(y>0)
            x--;
        else if(y<0)
            x++;
   }
   return x;
}

Sunday, December 26, 2010

Finding Words In Text Using JS RegExp

/**
 * Web application to search sentences that contain a word
 * supplied. 
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 27, 2010
 * @version : 1.0
 */


<div id="satu">
    This is a text. So you can do more with this one.
    Then make sure you type the word, not just a char
</div>
<input type="text" id="input"/>
<input type="button" value="Search"
     onclick="lol(document.getElementById('input').value)"/>
<div id="dua"></div>


<script>

function FindingWord(word){

    var doc = document.getElementById('satu');
    var text = doc.innerHTML;
    var desp = text.split(/[.]/g);

    var dua = document.getElementById('dua');
    var ol = document.createElement('ol');

    var pattern = new RegExp(word,"g");

    for(i=0;i&lt;desp.length;i++){
        code = desp[i].search(pattern);
        if(code!=-1){
            var li  = document.createElement('li');
            li.innerHTML = desp[i];
            dua.innerHTML = '';      
            ol.appendChild(li);
            dua.appendChild(ol);
        }
    }

}


</script>

Selection Algorithm Using C++

/**
 * Class provide implementation for selection algorithm
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 27, 2010
 * @version : 1.0
 */

class SelectionAlgorithm{
    private:
        int* data;
        int len;
    public:
        SelectionAlgorithm(int[],int);
        int getMinIndex();
        int getMaxIndex();
        int getMinValue();
        int getMaxValue();
};

SelectionAlgorithm::SelectionAlgorithm(int d[],int l){
    data = d;
    len = l;
}

int SelectionAlgorithm::getMinIndex(){
    int minIndex = 0;
    for(int i=1;i<len;i++){
        if(data[i]<data[minIndex]){
            minIndex = i;
        }
    }
    return minIndex;
}

int SelectionAlgorithm::getMaxIndex(){
    int maxIndex = 0;
    for(int i=1;i<len;i++){
        if(data[i]>data[maxIndex]){
            maxIndex = i;
        }
    }
    return maxIndex;
}

int SelectionAlgorithm::getMinValue(){
    int minValue = data[0];
    for(int i=1;i<len;i++){
        if(data[i]<minValue){
            minValue = data[i];
        }
    }
    return minValue;
}

int SelectionAlgorithm::getMaxValue(){
    int maxValue = data[0];
    for(int i=1;i<len;i++){
        if(data[i]>maxValue){
            maxValue = data[i];
        }
    }
    return maxValue;
}

Sort Selection Algorithm Using Java

/**
 * Class provide sorting algorithm based on sort selection
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 27, 2010
 * @version : 1.0
 */

class Sorting{


    /*
     * data array of integer
     */
    private int[] data;

    /*
     * len size of the data
     */
    private int len;

    /*
     * Constructor service
     * @param data array of integer
     */
    public Sorting(int[] data){
        this.data = data;
        this.len = this.data.length;
    }

    /*
     * method to get ascending series of the data
     * @return array in ascending order
     */
    public int[] getAsc(){       
        for(int i=0;i<this.len;i++){
            int minIndex = i;
            int tempValue = this.data[minIndex];
            for(int j=i;j<this.len-1;j++){
                if(this.data[j+1]<this.data[minIndex]){
                    minIndex = j+1;
                }
            }
            this.data[i] = this.data[minIndex];
            this.data[minIndex] = tempValue;
        }
        return this.data;
    }

    /*
     * method to get data in descending order
     * @return array in descending order
     */
    public int[] getDesc(){
        for(int i=0;i<this.len;i++){
            int maxIndex = i;
            int tempValue = this.data[maxIndex];
            for(int j=i;j<this.len-1;j++){
                if(this.data[j+1]>this.data[maxIndex]){
                    maxIndex = j+1;
                }
            }
            this.data[i] = this.data[maxIndex];
            this.data[maxIndex] = tempValue;
        }
        return this.data;
    }

}
       

Selection Algorithm Using Java

/**
 * Class to provide selection algorithm implementation
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 27, 2010
 * @version : 1.0
 */

class SelectionAlgorithm{

    /*
     * data array of integer
     */
    private int[] data;

    /*
     * len size of the data
     */
    private int len;


    /**
     * A constructor service
     * @param data array of integer
     */
    public SelectionAlgorithm(int[] data){
        this.data = data;
        this.len = this.data.length;
    }

    /**
     * method to get an index of min value of the data
     * @return minIndex int index of min value
     */
    public int getMinIndex(){
        int minIndex = 0;
        for(int i=1;i<this.len;i++){
            if(this.data[i]<this.data[minIndex]){
                minIndex = i;
            }
        }
        return minIndex;
    }

    /**
     * method to get an index of max value of the data
     * @return maxIndex int an index of max value
     */
    public int getMaxIndex(){
        int maxIndex = 0;
        for(int i=1;i<this.len;i++){
            if(this.data[i]>this.data[maxIndex]){
                maxIndex = i;
            }
        }
        return maxIndex;
    }

    /**
     * method to get min value
     * @return minValue int min value of the data
     */
    public int getMinValue(){
        int minValue = this.data[0];
        for(int i=1;i<this.len;i++){
            if(this.data[i]<minValue){
                minValue = this.data[i];
            }
        }
        return minValue;
    }

    /**
     * method to get max value
     * @return maxValue int max value of the data
     */
    public int getMaxValue(){
        int maxValue = this.data[0];
        for(int i=1;i<this.len;i++){
            if(this.data[i]>maxValue){
                maxValue = this.data[i];
            }
        }
        return maxValue;
    }

}
          

Factorial

/**
 * This function provide factorial service
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 26, 2010
 * @version : 1.0
 *
 * @param n number a factor of the factorial
 * @return sum total summing of the factor
 */

function factorial(n){
    if (n==0) return 1;
    else if (n<0) return 'invalid factor';
    var sum = 1;
    for(i=n;i>0;i--){
        sum = sum * i;
    }
    return sum;
}

Fibonaci Series

/**
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 26, 2010
 * @version : 1.0
 */

/**
 * This function provide fibonaci series
 * @param n number how many term expected
 * @return data an array of the series
 */
function fibo(n){
    var data = new Array();
    data[0]=1;
    data[1]=1;
    for(i=2;i<n;i++){
        data[i] = data[i-1]+data[i-2];
    }
    return data;
}

Selection Algorithm In Ruby

# Library for selection algorithm
#
# @author  : irfanudin ridho
# @email   : irfan.ub@gmail.com
# @date    : December 26, 2010
# @version : 1.0



# method to get the an index of the min value of the data
# @param data an array of the data
# @return minIndex int index of the min value
def getMinIndex(data)
    minIndex = 0
    len = data.length
    (1..len-1).each do |i|
        if(data[i]<data[minIndex])
            minIndex = i
        end
    end
    return minIndex
end


# method to get the an index of the max value of the data
# @param data an array of the data
# @return maxIndex int index of the max value
def getMaxIndex data
    maxIndex = 0
    len = data.length
    (1..len-1).each do |i|
        if(data[i]>data[maxIndex])
            maxIndex = i
        end
    end
    return maxIndex
end


# method to get min value of the data
# @param data an array of the data
# @return minValue min value of the data
def getMinValue data
    minValue = data[0]
    len = data.length
    (1..len-1).each do |i|
        if(data[i]<minValue)
            minValue = data[i]
        end
    end
    return minValue
end


# method to get max value of the data
# @param data an array of the data
# @return maxValue max value of the data
def getMaxValue data
    maxValue = data[0]
    len = data.length
    (1..len-1).each do |i|
        if(data[i]>maxValue)
            maxValue = data[i]
        end
    end
    return maxValue
end
           

Selection Algorithm In Python

# Class for implementation of Selection Algorithm
#
# @author  : irfanudin ridho
# @email   : irfan.ub@gmail.com
# @date    : December 26, 2010]
# @version : 1.0

class SelectionAlgorithm:
    def __init__(self,data):
        self.data = data
        self.len = len(data)

    def getMinIndex(self):
        minIndex = 0
        for i in range(1,self.len):
            if(self.data[i]<self.data[minIndex]):
                minIndex = i
        return minIndex

    def getMaxIndex(self):
        maxIndex = 0
        for i in range(1,self.len):
            if(self.data[i]>self.data[maxIndex]):
                maxIndex = i
        return maxIndex

    def getMinValue(self):
        minValue = self.data[0];
        for i in range(1,self.len):
            if(self.data[i]<minValue):
                minValue = self.data[i];
        return minValue;

    def getMaxValue(self):
        maxValue = self.data[0];
        for i in range(1,self.len):
            if(self.data[i]>maxValue):
                maxValue = self.data[i];
        return maxValue;

Selection Algorithm In C

/**
 * This function is an implementation of the selection algorithm.
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 26, 2010
 * @version : 1.0
 */


/**
 * This function will do give an index of the minimal value.
 * @param data array of integer of the data
 * @param len int length of the data
 * @return minIndex int an index of the min value
 */
int getMinIndex(int data[], int len){
    int minIndex = 0;
    int i;
    for(i=1;i<len;i++){
        if(data[i]<data[minIndex]){
           minIndex = i;
        }
    }
    return minIndex;
}




/**
 * This function will do give an index of the mmaximal value.
 * @param data an array of integer of the data
 * @param len int length of the data
 * @return maxIndex int an index of the min value
 */
int getMaxIndex(int data[], int len){
    int maxIndex = 0;
    int i;
    for(i=1;i<len;i++){
        if(data[i]>data[maxIndex]){
            maxIndex = i;
        }
    }
    return maxIndex;
}


/**
 * This function will do give the max value
 *
 * @param data an array of integer
 * @param len int length of the data
 * @return minValue int min value of the data
 */
int getMinValue(int data[], int len){
    int minValue = data[0];
    int i;
    for(i=1;i<len;i++){
        if(data[i]<minValue){
            minValue = data[i];
        }
    }
    return minValue;
}



/**
 * This function will do give the max value of the data
 *
 * @param data an array of integer
 * @param len length of the data array
 * @return maxValue int max value of the data
 */
int getMaxValue(int data[], int len){
    int maxValue = data[0];
    int i;
    for(i=1;i<len;i++){
        if(data[i]>maxValue){
            maxValue = data[i];
        }
    }
    return maxValue;
}