Question
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
using namespace std;
vector
int main() {
vector
vector
//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
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