Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

package Exercise3;

public class BinarySearchST, Value>

{

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)

{

}

}

ALGORITHM 3.2 Binary search (in an ordered array) public class BinarySearchST Key extends Comparableckey, Value> private Key] keys; private Value] vals; private int N; public BinarySearchST (int capacity) See Algorithm 1.1 for standard array-resizing code keys (Key []) new Comparable[capacity] vals-(Value[]) new Object[capacity]: public int sizeO return N public Value get(Key key) if (isEmptyO) return null; inti rank (key); if Ci ; j--) keys [] keys[j-1; vals[j] vals[j-1]; keys [i] = key; vals[i] = val; public void delete (Key key) // See Exercise 3.1.16 for this method<><>

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions