Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void insert(int value) {
- int lowerBound = 0;
- int upperBound = numOfElements;
- int currentIndex;
- while (true) {
- currentIndex = (lowerBound + upperBound) / 2;
- if (lowerBound >= upperBound) {
- break;
- } else {
- if (value > array[currentIndex]) {
- lowerBound = currentIndex + 1;
- } else {
- upperBound = currentIndex - 1;
- }
- }
- }
- for (int k = numOfElements; k > currentIndex; k--) {
- array[k] = array[k - 1];
- }
- array[currentIndex] = value;
- numOfElements++;
- }
Advertisement
Add Comment
Please, Sign In to add comment