Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you implement the below java program? import java.util.*; /** * A class that implements the ADT set by using a chain of linked nodes.

Can you implement the below java program? import java.util.*; /** * A class that implements the ADT set by using a chain of linked nodes. * The set is never full. * * */ public class LinkedSetWithChainOfNodes> implements SetInterface { private Node firstNode; // Head reference to first node public LinkedSetWithChainOfNodes() { //TODO Project2 } // end default constructor public void clear() { //TODO Project2 } // end clear public boolean add(T newEntry) { //TODO Project2 return false; //THIS IS A STUB } // end add /** * Locates a given entry within this set. * Returns a reference to the node containing the entry, if located, * or null otherwise. * * Utilized by removeElement method */ private Node getReferenceTo(T anEntry) { //TODO Project2 return null; //THIS IS A STUB } // end getReferenceTo public boolean removeElement(T anEntry) { //TODO Project2 return false; //THIS IS A STUB } // end remove public T remove() { //TODO Project2 return null; //THIS IS A STUB } // end remove public boolean contains(T anEntry) { //TODO Project2 return false; //THIS IS A STUB } // end contains public boolean isEmpty() { //TODO Project2 return false; //THIS IS A STUB } // end getLength public T[] toArray() { //TODO Project2 return null; //THIS IS A STUB } // end toArray // ****** IMPLEMENT THE FOLLOWING METHODS NOT DEFINED IN THE SetInterface ******** /** * Displays all elements in the set; * if the set is empty displays appropriate message * if the set is not empty displays the elements and the number of elements */ public void displaySet() { // TODO Project2 } // end displaySet /** * Checks if the given set called other is the same as the set * * @param o the other set to be compared with * @return true both sets are the same */ public boolean equals(Object o) { // TODO Project2 // one return statement per value returning method please return false; // THIS IS A STUB } /** * Gets the largest value in this set. * * @returns a reference to the largest object, or null if the set is empty */ public T getMax() { // TODO Project2 T largestValue = null; // one return statement per value returning method please return largestValue; } // end getMax /** * Removes and returns the smallest element in the set * * @return - null if the element was not found or the smallest element */ public T removeMin() { // TODO Project2 T smallestValue = null; // one return statement per value returning method please // the method must traverse the data with a while loop to find the smallest element // outside the loop should replace the found entry with the entry located in the firstNode and call remove() // TODO Project2 - the code in main written to test removeMin method is currently commented out // uncomment it when ready for testing return smallestValue; } /** * Removes from this set all entries that are larger than a given entry. * * @param anEntry the entry to be removed */ public void removeAllLarger(T anEntry) { // TODO Project2 // For efficiency it traverses the data and removes entries by changing pointers as needed // without calling any other method } // end removeAllLarger /** * Creates a new set that combines the contents of this set and a * second given set without affecting the original two sets. * * @param otherSet the given set * @return a set that is the union of the two sets */ public LinkedSetWithChainOfNodes union(LinkedSetWithChainOfNodes otherSet) { LinkedSetWithChainOfNodes unionSet = new LinkedSetWithChainOfNodes<>(); // TODO Project2 // one return statement per value returning method please return unionSet; } // end union /** * Creates a new set that contains those objects that occur in both this * set and a second given set without affecting the original two sets. * * @param otherSet the given set * @return a set that is the intersection of the two sets */ public LinkedSetWithChainOfNodes intersection(LinkedSetWithChainOfNodes otherSet) { LinkedSetWithChainOfNodes intersectionSet = new LinkedSetWithChainOfNodes<>(); // TODO Project2 // one return statement per value returning method please // call getReferenceTo(anElement) instead of contains return intersectionSet; } // end intersection /** * Creates a new set of objects that would be left in this set * after removing those that also occur in a second given set * without affecting the original two sets. * * @param otherSet the given set * @return a set that is the difference of the two sets */ public LinkedSetWithChainOfNodes difference(LinkedSetWithChainOfNodes otherSet) { LinkedSetWithChainOfNodes differenceSet = new LinkedSetWithChainOfNodes<>(); // TODO Project2 // one return statement per value returning method please // call getReferenceTo(anElement) instead of contains return differenceSet; } // end difference public void moveFirstToEnd() { //TODO Project2 // this method should run only if the chain has at least two nodes // do not create a new Node object (i.e. new Node<>()), just utilize // reference variables (i.e. Node someNode) to change appropriate pointers // method DOES NOT rely on the number of elements } // end moveToEnd /** * Replaces the first entry in this set with a given object. * * @param replacement the given object * @return the original entry in the set that was replaced or * null if empty chain or a duplicate */ public T replace(T replacement) { //TODO Project2 // change the data at the first node if appropriate return null; // THIS IS A STUB } // end replace /** * This method find the data in the middle node in one pass * * @return returns tha data in the middle node */ public T findMiddleElementInOnePass() { // TODO Project2 // uses two pointers - DOES NOT rely on the number of elements return null; // THIS IS A STUB } /** * Check if the linked list has loop in one pass * * @return returns true as soon as the first loop is found */ public boolean checkIfLoopExists() { // TODO Project2 // uses two pointers - DOES NOT rely on the number of elements return false; // THIS IS A STUB } Question: Please fill in the TODO 

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

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago