Question
Hi, Thank you for your time and expertise. I need your knowledge in solving this problem in C++11: Merge sort separates the array into 2
Hi,
Thank you for your time and expertise. I need your knowledge in solving this problem in C++11:
Merge sort separates the array into 2 parts, sorts them and then uses a temporary array to merge them. Merge sort does its job recursively.
MergeSort(A, upper, lower)
if upper = lower then
return
else
middle := (upper + lower) / 2
MergeSort(A, lower, middle)
MergeSort(A, middle + 1, upper)
Merge(A, lower, middle, upper)
end if
end MergeSort
Merge(A, lower, middle, upper)
n := upper - lower + 1
B := createArray(n)
pos := 0
left := lower
right := middle + 1
while left <= middle and right <= upper
if A[left] < A[right] then
B[pos] := A[left]
left := left + 1
else
B[pos] := A[right]
right := right + 1
end if
pos := pos + 1
end while
while left <= middle
B[pos] := A[left]
left := left + 1
pos := pos + 1
end while
while right <= upper
B[pos] := A[right]
right := right + 1
pos := pos + 1
end while
for pos := 0 to n - 1
A[pos + lower] := B[pos]
end for
end Merge
The merge sort algorithm sorts a vector of integers in descending order.
What are the next steps? What steps do I take to find the proper solution? Looking forward to your reply
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started