Translate the following pseudo code into Java: public boolean looseRemove(int ta
ID: 3568661 • Letter: T
Question
Translate the following pseudo code into Java:
public boolean looseRemove(int target)
{
find first index such that data[index]>=target;
if no such index found, index=count
if (target not found and isLeaf())
return false;
if (target found and isLeaf())
remove target from data array;
shift contents to the left and decrement count
return true;
if (target not found and root has children)
{
subset[index].loose_remove(target);
if(subset[index].dataCount < MINIMUM)
fixShortage(index);
return true;
}
if (target found and root has children)
{
subset[index].removeLargest(data[index]);
if(subset[index].dataCount < MINIMUM)
fixShortage(index);
return true;
}
Explanation / Answer
private boolean looseremove(int target)
{
int i = firstge(target)
if(!contains(target) && isleaf())
{
return false;
}
else if(contains(target) && isleaf())
{
subset[i].looseremove(target);
fixshortage(index);
;
return true;
}
if(!contains(target) && subset[i].contains(target))
{
subset[i].looseremove(target);
if(subset[i].datacount<minimum)
fixshortage(i);
return true;
}
if (target not found and root has children)
{
subset[index].loose_remove(target);
if(subset[index].datacount < minimum)
fixshortage(index);
return true;
}
}
int firstge(target)
{
int index=0;
boolean f= false;
int temp=data[0];
for(int i=0;i<data.length;i++)
{
if ( data[i] >= target)
{
temp=data[i];
index=i;
f=true;
break;
}
else{
f=false;
}
}
if(f)
{
return index;
}
else
{
return index=datacount;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.