Merge Sort In C The implementation for Mergesort given in Se

Merge Sort In C++

The implementation for Mergesort given in Section 7.4 takes an array as input and sorts that array. At the beginning of Section 7.4 there is a simple pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked list-based version of Mergesort and the array-based version of Mergesort, and compare and analyze their running times.

Solution

Merge sort for linked list:

Merge sort is often preferred for sorting a linked list.SortedMerge() should return the new list. The new list should be made by splicing together the nodes of the first two lists (use MoveNode()). Ideally, Merge() should only make one pass through each list. Merge() is tricky to get right — it may be solved iteratively or recursively. There are many cases to deal with: either \'a\' or \'b\' may be empty, during processing either \'a\' or \'b\' may run out first, and finally there\'s the problem of starting the result list empty, and building it up while going through \'a\' and \'b\'.

O(log n)

Merge sort for array based

Merge Sort In C++ The implementation for Mergesort given in Section 7.4 takes an array as input and sorts that array. At the beginning of Section 7.4 there is a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site