的每一個最大數我有3種int類型:最有效的方法來查找一組數字
int value1;
int value2;
int value3;
而3布爾值:
bool maxIs1;
bool maxIs2;
bool maxIs3;
的輸入值必須是獨立的變量。
maxIs1 = True
表示value1
必須具有最大值等。
我需要方法來比較這組數字與一組條件。 例如:
int value1 = 10;
int value2 = 1;
int value3 = 10;
bool maxIs1 = True;
bool maxIs2 = False;
bool maxIs3 = True;
bool result = compareValues(); //true
或者:
int value1 = 1;
int value2 = 1;
int value3 = 10;
bool maxIs1 = True;
bool maxIs2 = False;
bool maxIs3 = True;
bool result = compareValues(); //false
什麼是最有效的方式來做到這一點?
是變量不變(3)或有可能是其他變量的量? –
在我的情況下,這裏只有3. – InfernumDeus
如果你擔心效率和超過3個值,這是一個'O(n)'問題,你只需要迭代一次輸入。 – Rawling