2 回答

TA贡献1818条经验 获得超3个赞
我希望将此作为评论,但是我还没有足够的声誉,所以我来回答。
就个人而言,我将为此使用某种Map,其速度可能高达O(1),其中遍历数组时是O(N)(或O(N / 2)?)。但是这里是如何根据提供的数据进行高/低的计算。我不了解ComboBox界面。
void select_year(int year_selected) {
for(int i = 0 ; i < yearTemp.length ++i) {
if((i* 2) + 1 > highLowTemp.length)
throw Exception("bad data"); // probably handle this better
int year = yearTemp[i]
if(year_selected == year) {
int low = highLowTemp[i * 2]
int high = highLowTemp[(i * 2) + 1]
// this is the high and low for the year_selected
// do stuff with it
// edit: break from here when you are done
}
}
}
添加回答
举报