Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Quick sort make sure the output is exactly the same as the example below nothing more or nothing less: Quick sort is one ofthe 0(n

Quick sort

make sure the output is exactly the same as the example below nothing more or nothing less:

image text in transcribedimage text in transcribed
Quick sort is one ofthe 0(n log n) sorts we consider. it relies on the idea of recursively splitting a list into smaller sublists using a pivot, and sorting them. - The program should read in the number of values as an integer allocate the necessary space then read in all the values provided. Use a helper functiony ReadNumsO to return the dynamic array instead of inputting the values in main(). - Create a function called PrintNumsO that prints out the array between a start and end index(inclusive). It should take as parameters the array as well as the starting and stopping indices in the array It should print out the array between those index values with a space between each number but no space at the end. Finish with a new line. - Complete a recursive function, QuickSortO. You may wish to use a helper function to compute the partition. for splitting the array. Always select the pivot as the right-most element in the array. Add code to the sort algorithm to count the number of swaps performed to output the pivot and pivoted array before each recursive call; and to output the state ofthe sub-arrays after each recursive call. Add code at the end of main() that outputs "Swaps" followed by the number of swaps (EX: "Swaps: 2"). Hint: Use a global variable to count the swaps. Note: Ta ke special care to look at the output of each test to better understand the quick sort algorithm. Ex: When the input is: 6321598 The output is: Unsorted: 3 2 1 5 9 8 Pivot: 8 3 2 1 5 8 9 Pivot: 5 3 2 1 5 Pivot: l 1 2 3 Left Side: Pivot: 3 2 3 Left Side: 2 Right Side: Right Side: 2 3 Left Side: 1 2 3 Right Side: Left Side: 1 2 3 5 Right Side: 9 Sorted: l 2 3 5 8 9 Swaps: 2

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions