Ok so I want to find an algorythm that searches through some objects (in my case 4) and finds the object with the smallest member variable. Lets say you can get that value with object.getIntegerValue()
In my case I have 4 android layouts and want to find the layout with the smallest amount of childs.
I think there will be plenty of solutions but I just want to find a fast one. No matter how dirty and so on....
My Code so far is short, dirty and doesnt always return the object with the smallest member variable, but only has to serve as an Code Example here:
private LinearLayout layoutChanger(){
int one, two, three;
one = layoutOne.getChildCount();
if ((two = layoutTwo.getChildCount()) <= one) {
if ((three = layoutThree.getChildCount()) <= two) {
if ((layoutFour.getChildCount()) <= three)
return layoutFour;
return layoutThree;
}
return layoutTwo;
}
return layoutOne;
}
Edit: I know how to do this I rather wanted to get suggestions on how to speed up things...
Is Comparable really a fast one? Or should I distinct myself of OOP solutions to get better performance?
threeis the smallest, your method will never indicate that as long astwo>one. Instead, it will return the value oftwoand will never test the value ofthree.