Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this lab, you will first populate an array with integer values provided by a user and then you wau sur L the array. You
For this lab, you will first populate an array with integer values provided by a user and then you wau sur L the array. You will implement ve quicksort algorithm. Quicksort Algorithm Quicksort, also known as the partition-exchange sort, is an efficient algorithm From Wikipedia: Quicksort first divides a large array into two smaller subarrays the low elements and the high elements. Quicksort can then recursively sort the sub-arrays l, Pick an element, called a pivot, from the array. 2. Reorder the array so that all elements with values less than the pivor come before the pivot, while all elements with values greater than the pivot come after it (equal values cango either way). After this partitioning. the pivor is in its final position. This is called the partition operation. 3. Recursively apply the above steps to the sub-array of elements with smaller values and separately to the sub-array of elements with greater values. The base case of the recursion is arrays of size zero or one. which never need to be sorted. Implementation At the top of your program, define a constant to restrict the maximum size of your array: #define MAXLARRAYLSIZE 50 You will implement 5 functions as well as your main function. The function prototypes are: int populate array int array[] Fill array with values from user. void print array int array int n Print out the array values void swap( int array int index1, int index Swap two array elements. void quicksort( int array int low, int high Sorting algorithm int partition nt low, int hieh ind the partition point (pivot array These function prototypes will appear near the beginning of the program. Later in the program, you will provide the function implementation (you repeat the function prototype but this time you provide the function body as well). main Function 1. in your main function, declare an array of size MAx ARRAY SIZE 2. Next. call your function populate array described below) and save the result as variable n. 3. Print out the value in the array by calling your function print array (described below). 4. Now call your sorting algorithm with the line: quicksort ay, a, n-1)
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