Question: Set.java This class represents a simple collection that must be implemented with a singly-linked list. This class must work for the generic type T. The

 Set.java This class represents a simple collection that must be implemented

Set.java This class represents a simple collection that must be implemented with a singly-linked list. This class must work for the generic type T. The class must have the following private variable: - LinearNode setStart (the front of the linked list) The class must have the following public methods: - public Set(): constructor - Initialize setStart to null - public void add(T element) - Create a new node containing the given element and add the new node to the linked list. The order does not really matter for a Set, so you can either add to the end or the start of the linked list for simplicity. Make sure you update the links properly and account for different cases (i.e. adding the first node to an empty list, adding a node to a list with other nodes, etc.) - public int getLength() - Return the number of items in the linked list - public T getElement(int i) - Returns the element stored in the ith node of the linked list (NOTE: remember that order does not matter, so this method is not being tested in the autograded tests but it may be very useful for you when implementing the Counter class and you need to extract individual elements from a Set within a loop). - public boolean contains(T element) - Returns true if the given element is found within the linked list; false otherwise - public String toString() - Returns a string containing each of the elements in the Set separated by a space

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!