Answered step by step
Verified Expert Solution
Link Copied!

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 3 methods that are left out in java. This program is an implementation of the data structure binary search tree sorted list. the 3 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 =0;
}
//FILL IN IMPLEMENTATION OF METHODS BELOW
// Adds a new entry to the sorted List
public void add(T newEntry){
list.add(newEntry);
numberOfEntries++;
}
//Removes the first entry in the sorted List
public boolean remove(T anEntry){
if (list.contains(anEntry)){
list.remove(anEntry);
numberOfEntries--;
return true;
}
return false;
}
// Removes the entry at a given position from this list.
public T remove(int givenPosition){
if (givenPosition <1|| givenPosition > getLength()){
throw new IndexOutOfBoundsException("Invalid position for removal.");
}
T removedEntry = list.getEntry(givenPosition);
remove(removedEntry);
return removedEntry;
}
public getEntry(){
// fill in here
}
public getPosition(){
// fill in here
}
public boolean contains(T anEntry){
return list.contains(anEntry);
}
public void clear(){
list.clear();
numberOfEntries =0;
}
public int getLength(){
return numberOfEntries;
}
public boolean isEmpty(){
return numberOfEntries ==0;
}
public toArray(){
// fill in here
}
}/**
An interface for the ADT sorted list.
Entries in the list have positions that begin with 1.
@author Frank M. Carrano
@author Timothy M. Henry
@version 5.0
*/
public interface SortedListInterface>
{
/** Adds a new entry to this sorted list in its proper order.
The list's size is increased by 1.
@param newEntry The object to be added as a new entry. */
public void add(T 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 remove(T 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 1.
@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 <1 or givenPosition > getLength().*/
public T remove(int 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 <1 or givenPosition > getLength().*/
public T getEntry(int 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 getPosition(T 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 contains(T 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

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

=+ What is the group processes perspective?

Answered: 1 week ago