- #1
pumas
- 15
- 0
I'm supposed to create a method that adds intergers to an array and keep it in sorted order. I'm supposed to search for the number in the array using binarySearch. I get an error that says arrayOutOfBound I don't know how to fix this. I have written the following code:
elementData is the array,
I appreciate any help
elementData is the array,
Code:
public void add(int value) {
int index = binarySearch(elementData,value,0, size - 1);
}
for (int i = size; i > index; i--)
{
elementData[i] = elementData[i - 1];
elementData[index] = value;
size++;
}
}
I appreciate any help