Question: In java, implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as
In java, implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as single, double, circular lists, stacks andor queues. You can populate your list from an explicitly defined array in your program.
HINT: You will not be using low, middle and high anymore. For finding the middle point, traverse through the linked list while keeping count of the number of nodes. Break up the list into two, null terminated lists, based on the node count.
The mergesort function should accept only a single linked list and it should return a linked list. The merge function should take linked lists and also return a linked list. The look of the function will be very similar to the array version of the mergesort algorithm. You should not use any of the builtin classes or functions. You have to create your linked list.
Here is a portion of what mergeSort function would look like:
a points to the left partition, b points to the right partition. They would be passed by reference.
You would then recursively process each partition.
ifheadNULL
return NULL;
if headnextNULL
return head;
amergeSorta;
bmergeSortb;
cmergeab;
return c;
These are the function headers
void split node head,node&anode&b
node mergenode a node b
node mergeSort node head
Make sure to account for when head is null or when there is only one item in the list
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
