Question: In the class LinkedList below, implement the method LinkedList partition(E elem). This instance method partitions this list in two parts. This intance retains all the
In the class LinkedList below, implement the method LinkedList partition(E elem). This instance method partitions this list in two parts. This intance retains all the leftmost elements of this list up to and including the first occurrence of elem. The rest of the elements are returned as a new list. If elem is not found in the list, then this list remains intact and the returned list is empty. For instance, let xs designate a list containing the values 1, 2, 3, 4, 3, 5, 6. After the call ys = xs.partition(3), the list designated by xs contains the elements 1, 2, 3, whereas ys now designates a list containing the elments 4, 3, 5, 6. The method must be implemented following the technique presented in class for implementing recursive methods inside the class, i.e. where a recursive method is made of a public part and a private recursive part, which we called the helper method. The public method initiates the first call to the recursive method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
