Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package p5_SortedArrayAccess; import java.util.*; public class sortedArrayAccess { public static double[] arr; private int arraySize; public sortedArrayAccess(int scale) { arr = new double[scale]; arraySize =

image text in transcribed
package p5_SortedArrayAccess;
import java.util.*;
public class sortedArrayAccess
{
public static double[] arr;
private int arraySize;
public sortedArrayAccess(int scale)
{
arr = new double[scale];
arraySize = 0;
}
public final double get(int i)
{
return arr[i];
}
public final int BinarySearch(double Key)
{
int k = 0;
int lower = 0;
int upper = arraySize - 1;
while (lower
{
k = (lower + upper + 1) / 2;
if (Key == arr[k])
{
break;
}
if (Key
{
upper = k - 1;
}
else
{
lower = k + 1;
}
}
if (lower == upper)
{
k = lower;
}
if (Key == arr[k])
{
return k;
}
else
{
System.out.println("The item cannot be found!");
return -1;
}
}
public final void insertion(double Key, double Item)
{
if (arraySize == 0)
{
arr[0] = Item;
}
/* find the position for interting the given item */
int position = 0;
while (Key > arr[position] && position
{
position++;
}
for (int i = arraySize; i > position; i--)
{
arr[i] = arr[i - 1];
}
arr[position] = Item;
arraySize = arraySize + 1;
}
public final void deletion(double Key)
{
/* find the given item */
int position = BinarySearch(Key);
if (position != -1)
{
for (int i = position; i
{
arr[i] = arr[i + 1];
}
arraySize = arraySize - 1;
};
}
public final void display()
{
if (arraySize != 0)
{
for (int i = 0; i
{
System.out.println(arr[i]);
}
};
System.out.println("The number of items is " + arraySize);
}
}
4.2 Download and study program P1-2 Add a testing class that can test all the operations defined in the sortedArrayAccess class. Make your testing menu-driven

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago