A linear search traverse down a list, one item at a time, without jumping.
public String linearSearchForValue(int value) {
String indexesWithValue = "";
for (int i = 0; i < size; i++) {
if (theArray[i] == value) {
indexesWithValue += i + " ,";
}
}
return indexesWithValue;
}
No comments:
Post a Comment