Question: How would you implement these functions in C++? void MergeSort(list & S); // MergeSort for list list & Merge(list & C, list & A, list

How would you implement these functions in C++?

void MergeSort(list& S); // MergeSort for list

list& Merge(list& C, list& A, list& B); // Merge for list

Merge Sort - Pseudocode

Algorithm MergeSort(S) if S.size() > 1 (S1, S2) = partition(S, n/2) mergeSort(S1) mergeSort(S2) S = merge(S1, S2) 

Merge - Pseudocode

Algorithm Merge(A, B) C = empty list while (!A.isEmpty() and !B.isEmpty()) if A.first().element() < B.first().element() C.insertLast(A.remove(A.first())) else C.insertLast(B.remove(B.first())) while (!A.isEmpty() C.insertLast(A.remove(A.first())) while (!B.isEmpty() C.insertLast(B.remove(B.first())) return C 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!