Pages

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, December 30, 2010

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()]
 

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;