java - Finding object with smallest member variable -
ok want find algorythm searches through objects (in case 4) , finds object smallest member variable. lets can value object.getintegervalue()
in case have 4 android layouts , want find layout smallest amount of childs.
i think there plenty of solutions want find fast one. no matter how dirty , on....
my code far short, dirty , doesnt return object smallest member variable, has serve code example here:
private linearlayout layoutchanger(){ int one, two, three; 1 = 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: know how rather wanted suggestions on how speed things...
is comparable fast one? or should distinct myself of oop solutions better performance?
just example:
int childcount; layout[] mylayouts = {layoutone,layouttwo,layoutthree}; layout selected; for(layout layout:mylayouts){ if(childcount=0 || childcound>layout.getchildcount()) { selected = layout; childcount = layout.getchildcount(); } } return layout;
Comments
Post a Comment