Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill in the method stub below in C# to sort the specified portion of the the giv

ID: 3581615 • Letter: F

Question

Fill in the method stub below in C# to sort the specified portion of the the given array by forming three smaller sorted portions and merging them into one sorted portion. The portion of the array to be sorted begins at index start and has len elements. The three smaller sorted portions should have the same length as nearly as possible, and should together comprise the entire portion to be sorted. [Hint: For a length of n, the lengths n/3, (n + 1)/3, and (n + 2)/3 (using integer division) satisfy this requirement.]

Your code may call the following method, which you do not need to write:

private void Merge(decimal[] a, int start, int len1, int len2, int len3)

The Merge method above merges three sorted portions of a into a single sorted portion, where

• the first sorted portion begins at index start and has len1 elements;

• the second sorted portion occurs immediately following the first sorted portion and has len2 elements; and

• the third sorted portion occurs immediately following the second sorted portion and has len3 elements.

You may assume that a is a non-null array containing at least start + len elements, and that start and len are both nonnegative. You may not use any loops — use recursion instead. You may not call any methods other than Merge (above) and Sort (recursively). You may not add any code outside of the Sort method.

private void Sort(decimal[] a, int start, int len)

{

}

Explanation / Answer

private void Sort(decimal [ ] a, int start, int len)
{
   int i = 0;
   while (i < 3)
  
{

   int s = (i+1)*start;
int e = len/3;
     
int mid;
     
if (s > e)
{
  
mid = (e + s) / 2;
Sort(a, s, mid);

  Sort(a, (mid + 1), e);

   }
   i++;
}
     
Merge(a, start, len1, len2, len3);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote