我想知道 find 和 replaceAll 方法的最佳、最差和平均情况以及增长函数,它基本上是在以下代码中数组大小大于零的每种情况下执行的语句数
/**
* Return index where value is found in array or -1 if not found.
* @param array ints where value may be found
* @param value int that may be in array
* @return index where value is found or -1 if not found
*/
public static int find(int[] array, int value) {
for (int i = 0; i < array.length; i++) {
if (array[i] == value) {
return i;
}
}
return -1;
}
/**
* Replace all occurrences of oldValue with newValue in array.
* @param array ints where oldValue may be found
* @param oldValue value to replace
* @param newValue new value
*/
public static void replaceAll(int[] array, int oldValue, int newValue) {
int index = find(array, oldValue);
while (index > -1) {
array[index] = newValue;
index = find(array, oldValue);
}
}
蝴蝶不菲
qq_遁去的一_1
米脂
相关分类