Write a java class named First_Last_Recursive_Merge_Sort that implements the recursive algorithm for Merge Sort.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Write a java class named First_Last_Recursive_Merge_Sort that
implements the recursive
You can use the structure below for your implementation.
public class First_Last_Recursive_Merge_Sort {
//This can be used to test your implementation.
public static void main(String[] args) {
final String[] items = {"Zeke", "Bob", "Ali", "John",
"Jody", "Jamie", "Bill", "Rob", "Zeke", "Clayton"};
display(items, items.length - 1);
mergeSort(items, 0, items.length - 1);
display(items, items.length - 1);
}
private static <T extends Comparable<? super T>>
void mergeSort(T[] a, int first, int last)
{
//<Your implementation of the recursive algorithm for Merge Sort
should go here>
} // end mergeSort
private static <T extends Comparable<? super T>>
void merge(T[] a, T[] tempArray, int first,
int mid, int last)
{
//<Your implementation of the merge algorithm should go here>
} // end merge
//Just a quick method to display the whole array.
public static void display(Object[] array, int n)
{
for (int index = 0; index < n; index++)
System.out.println(array[index]);
System.out.println();
} // end display
}// end First_Last_Recursive_Merge_Sort
Trending now
This is a popular solution!
Step by step
Solved in 2 steps