First you need to implement both the MERGE-
SORT and MERGE algorithms (shown below). The main ( ) function of the program carries out the
following tasks:
1. Ask the user to input the value of n, where 1< n s 50
2. Fill A with random integers in the range 0 to 100. To generate such random numbers, you need to
use the <random> header. Check the following link for an example:
http://en.cppreference.com/w/cpp/numeric/random/uniform int distribution
3 .
Call the MERGE-SORT function to sort the contents of A. MERGE(A. p. q, r)
MERGE-SORT needs to call the MERGE function.
4.
Display on the screen the contents of the sorted array A.
m1 =q-p+1
2
n2 = r -q
3
let L[1 . . n, + 1] and R[1 . .n2 + 1]
MERGE-SORT (A, p, r)
be new arrays
1
if p < r
4
for i = 1 to n 1
q = [(p + r) /21
5
L[i] = Alp +i -1]
VIA W
6
for j = 1 to n2
MERGE-SORT(A, P. q)
7
Rli] = A[q + j]
MERGE-SORT(A, q + 1, r)
8 L[n + 1] = 00
MERGE(A, p, q, r)
9 R[n2 + 1] = 00
10 i = 1
11 j = 1
12
for k = p tor
13
if L[i] < RLj]
14
A[k] = L[i]
15
i =i+1
16
else A[k] = R[j ]
17
j = j+1
Problem
In the above MERGE algorithm and to avoid having to check whether either list is empty in each basic step,
a sentinel value of co is placed at the end of each list.
Rewrite the algorithm (no need to submit any C++ program code) so that it does not use sentinels,
instead it stops once either array L or R has had all its elements copied back to A and then copying the
remainder of the other array back into A.