Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 8. Partition around median. Given a vector A of distinct integers and given k, the median of A (the median might be a decimal

Problem 8. Partition around median. Given a vector A of distinct integers and given k, the median of A (the median might be a decimal number, e.g. 3.2). Partition items of A so that all items in the first half of A are less than or equal to k and a items in the second half of A are greater than k. Write a function that partitions integers of A in place (do not use any additional data structure) and does the fewest number of operations (such as comparisons, assignments) You need to write the following function with the exact header as shown: int partitionAround(vectorcint> &A, double k); (Note that vector A is passed by reference, but not const, because this function will change A)

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions