Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Unit 4 Assignment 3: Coding Project (Quick Sort) Scenario Use the studentGrades array from task 1. Implement a quicksort that will sort the grades highest

Unit 4 Assignment 3: Coding Project (Quick Sort)

Scenario

Use the studentGrades array from task 1. Implement a quicksort that will sort the grades highest to lowest and lowest to highest.

Create one method called sortArrayDes(). Implement a quicksort algorithm that will sort from highest to lowest.

Create a second method called sortArrayAsc(). Implement a quicksort algorithm that will sort from lowest to highest.

Create a third method called printArray, which will display the results of both sorts.

Expected Output

Quicksort Descending

98 97 95 90 88 78 75 65 56 55

Quicksort Ascending

55 56 65 75 78 88 90 95 97 98

This is what I have so far (I use C#):

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace ConsoleApp45 { public static class QuickSort { public static void Sort(T[] array) where T : IComparable { Sort(array, 0, array.Length - 1); } private static void Sort(T[] array, int lower, int upper) where: { if (lower < upper) { int p = Partition(array, lower, upper); Sort(array, lower, p); Sort(array, p + 1, upper); } } }private static int Partition(T[] array, int lower, int upper) where: { int i = lower; int j = upper; T pivot = array[lower];

do { while (array[i].CompareTo(pivot) < 0) { i++; } while (array[j].CompareTo(pivot) > 0) { j--; } if (i >= j) { break; } Swap(array, i, j); } while (i <= j); return j; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Prove that 2n () + (G) +- C) - (")

Answered: 1 week ago

Question

Evaluating Group Performance?

Answered: 1 week ago