Question
Write a c++ program for the following function that partitions the list using the first element, called a pivot: int partition(int list[], int size) After
Write a c++ program for the following function that partitions the list using the first element, called a pivot:
int partition(int list[], int size)
After the partition, the elements in the list are rearranged so that all the elements before the pivot are ;ess than or equal to the pivot and the elements after the pivot are greater than the pivot. The function also returns the index where the pivot is located in the new list. For example suppose the list is {5,2,9,3,6,8}. After the partition, the list becomes {3,2,5,9,6,8}. Implement the function in a way that takes size number of comparisons.
Write a test program that prompts the user to enter a list and displays the list after the partition. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. This number is not part of the list. Assume the maximum list size is 10.
Enter list: 8 10 1 5 16 61 9 11 1
After the partition, the list is: 9 1 5 1 10 61 11 16
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