Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java method in the LinkedList class with the following header: public in

ID: 3935447 • Letter: W

Question

Write a Java method in the LinkedList class with the following header: public int[] toArray() The method should return a newly-allocated array of int values, containing all of the elements in the linked list in the same order as they are stored in the list. The array should have the same size as the list. Write a recursive Java method with the following header: public int recMinimum (int[] values, int start, int end) The method should return the minimum value stored in the array between "start" and "end" including both endpoints. For example. recMinimum([3, -1, 5, 2, -5], 0, 3) should return -1. You may assume that (0

Explanation / Answer

Here is the code for you:

public static int[] addElement(int[] x, int element)
{
x = Arrays.copyOf(x, x.length + 1);
x[x.length - 1] = element;
return x;
}
public int[] toArray(Node head)
{
Node current = head;
int[] z = new int[0];
while(current != null)
{
addElement(z, current.getDatum());
current = current.getNext();
}
return z;
}

public int recMinimum(int[] values, int start, int end)
{
if(start == end)
return values[start];
return values[start] < recMinimun(values, start+1, end) ? values[start] : recMinimum(values, start+1, end);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote