The following exercises gives you practice with concepts that may show up on the quiz. Solutions to
Question:
The following exercises gives you practice with concepts that may show up on the quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with the TAs during office hours. It is recommended that you try these exercises on paper first (without using a computer).
Exercises
1. Implement the methods below based on the following Java class definitions. For recursive methods you may only add one auxiliary function, and you may not add any instance nor static variables.
public class LinkedList> { private class Node {
private T data;
private Node next;
private Node(T data) {
this.data = data;
next = null; }
}
private Node head;
public LinkedList() { head = null;
} }
a. Define a constructor that takes a TreeSet as a parameter and initializes a linked list with the elements in the set. The new list must be sorted in increasing lexicographic order.
b. Define a RECURSIVE method named size that returns the number of elements in the list. The prototype for this method is:
public int size()
c. Define a RECURSIVE method named inRange that returns a HashSet with the elements in the list that in the specified range. The range includes the lower and upper bound. The prototype for this method is:
public HashSet inRange(T lowerBound, T upperBound)
d. Define a RECURSIVE method named remove that removes all instances in the list that are equal to the target parameter. The prototype for this method is:
public void remove(T target)
e. Define a RECURSIVE method named positionOfElementInList that returns a TreeMap that maps each element of the list to its position in the list. The prototype for this method is:
f.public TreeMap positionOfElementInList()
Define an equals method for the class. Two lists are equal if the data elements in the two lists are the same (and appear in the same position).
Transportation A Global Supply Chain Perspective
ISBN: 9781337406642
9th Edition
Authors: Robert A. Novack, Brian Gibson, Yoshinori Suzuki, John J. Coyle