Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please complete the 3 methods that are left out in java. This program is an implementation of the data structure binary search tree sorted list.
Please complete the methods that are left out in java. This program is an implementation of the data structure binary search tree sorted list. the methods that need to be done are getPosition, toArray, and getEntry. You can leave everything else the same. please use iterators to implement those methods. here is the code import java.util.Iterator;
import java.util.NoSuchElementException;
import TreePackage.;
public class BSTSortedList
implements SortedListInterface
private BinarySearchTree list; the sorted list, represented as a BST
private int numberOfEntries; number of entries currently in list
default constructor list is initially empty
public BSTSortedList
list new BinarySearchTree;
numberOfEntries ;
FILL IN IMPLEMENTATION OF METHODS BELOW
Adds a new entry to the sorted List
public void addT newEntry
list.addnewEntry;
numberOfEntries;
Removes the first entry in the sorted List
public boolean removeT anEntry
if listcontainsanEntry
list.removeanEntry;
numberOfEntries;
return true;
return false;
Removes the entry at a given position from this list.
public T removeint givenPosition
if givenPosition givenPosition getLength
throw new IndexOutOfBoundsExceptionInvalid position for removal.";
T removedEntry list.getEntrygivenPosition;
removeremovedEntry;
return removedEntry;
public getEntry
fill in here
public getPosition
fill in here
public boolean containsT anEntry
return list.containsanEntry;
public void clear
list.clear;
numberOfEntries ;
public int getLength
return numberOfEntries;
public boolean isEmpty
return numberOfEntries ;
public toArray
fill in here
An interface for the ADT sorted list.
Entries in the list have positions that begin with
@author Frank M Carrano
@author Timothy M Henry
@version
public interface SortedListInterface
Adds a new entry to this sorted list in its proper order.
The list's size is increased by
@param newEntry The object to be added as a new entry.
public void addT newEntry;
Removes the first or only occurrence of a specified entry
from this sorted list.
@param anEntry The object to be removed.
@return True if anEntry was located and removed;
otherwise returns false.
public boolean removeT anEntry;
Removes the entry at a given position from this list.
Entries originally at positions higher than the given
position are at the next lower position within the list,
and the list's size is decreased by
@param givenPosition An integer that indicates the position of
the entry to be removed.
@return A reference to the removed entry.
@throws IndexOutOfBoundsException if either
givenPosition or givenPosition getLength
public T removeint givenPosition;
Retrieves the entry at a given position in this list.
@param givenPosition An integer that indicates the position of
the desired entry.
@return A reference to the indicated entry.
@throws IndexOutOfBoundsException if either givenPosition or givenPosition getLength
public T getEntryint givenPosition;
Gets the position of an entry in this sorted list.
@param anEntry The object to be found.
@return The position of the first or only occurrence of anEntry
if it occurs in the list; otherwise returns the position
where anEntry would occur in the list, but as a negative
integer.
public int getPositionT anEntry;
Sees whether this list contains a given entry.
@param anEntry The object that is the desired entry.
@return True if the list contains anEntry, or false if not.
public boolean containsT anEntry;
Removes all entries from this list.
public void clear;
Gets the length of this list.
@return The integer number of entries currently in the list.
public int getLength;
Sees whether this list is empty.
@return True if the list is empty, or false if not.
public boolean isEmpty;
Retrieves all entries that are in this list in the order in which
they occur in the list.
@return A new
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