Question
can i get delete method for the below mentioned code package Exercise3; public class BinarySearchST , Value> { private Key[] keys; private Value[] vals; private
can i get delete method for the below mentioned code
package Exercise3;
public class BinarySearchST
{
private Key[] keys;
private Value[] vals;
private int N;
public BinarySearchST(int capacity)
{
keys = (Key[]) new Comparable[capacity];
vals = (Value[]) new Object[capacity];
}
public int size()
{
return N;
}
public Value get(Key key)
{
if(isEmpty())
return null;
int i= rank(key);
if(i
return vals[i];
else
return null;
}
public int rank(Key key)
{
int lo=0,hi=N-1;
while(lo
{
int mid=lo+(hi-lo)/2;
int cmp=key.compareTo(keys[mid]);
if(cmp
hi=mid-1;
else if(cmp>0)
lo=mid+1;
else
return mid;
}
return lo;
}
public void put(Key key,Value val)
{
int i=rank(key);
if(i { vals[i]=val; return; } for(int j=N;j>i;j--) { keys[j]=keys[j-1]; vals[j]=vals[j-1]; } keys[i]=key; vals[i]=val; N++; } public void delete(Key key) { } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started