Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi Learning C++ here and trying to do some practice. Write a C++ function that has a vector of ints as a parameter and returns

Hi Learning C++ here and trying to do some practice.

Write a C++ function that has a vector of ints as a parameter and returns a different vector of ints with the values sorted. Write the header in such a way that the function cannot alter any values in the incoming vector and that the function does not automatically make a copy of the entire incoming vector. In the body, copy the incoming vector's values into a new vector and then sort the new vector using your own code, not a built-in sorting function. On the real exam, you will be given a different operation to do on the incoming vector (an easier one!), but the concept of passing a vector to a function and returning a vector from a function will be the same. In a comment above the function list the runtime efficiency (for example 3n2+ 2n + 5) and the growth rate in Big-O notation.

So I'm bit stuck on sorting the vector of ints and make the copy of it.

so far,

#include #include #include

using namespace std;

vector sort(const vector& list);

int main() {

vector nums = { 2, 6, 3, 67, 1, 15 }; vector sortedNums = sort(nums); }

vector sort(const vector& list) { vector sortedList; //make copy of list

//sort the copy

//return copy return sortedList; } I was wondering what type of 'sort' I need to use and how to make it show the original unsorted arrays and the sorted arrays.

Please help thank you.

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions