/**
* 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;
}
No comments:
Post a Comment