Pages

Sunday, December 26, 2010

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;

No comments:

Post a Comment