Question: 15.15LAB: Sort a vector A program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The

15.15LAB: Sort a vector

A program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers.

Ex: If the input is:

5 10 4 39 12 2 

the output is:

2 4 10 12 39 

For coding simplicity, follow every output value by a space, including the last one.

Your program must define and call the following function. When the SortVector function is complete, the vector passed in as the parameter should be sorted.

void SortVector(vector& myVec)

Hint: There are many ways to sort a vector. You are welcome to look up and use any existing algorithm. Some believe the simplest to code is bubble sort:https://en.wikipedia.org/wiki/Bubble_sort. But you are welcome to try others:https://en.wikipedia.org/wiki/Sorting_algorithm.

Code:

#include

#include

using namespace std;

void SortVector(vector& myVec)//function for sorting

{

sort(myVec.begin(), myVec.end());//sort function to sort from start to end

}/* Define your function here */

int main() {

int n;//for number of elements

cin>>n; //first input is number of elements

vector myVec(n); //vector for integers

for (int i=0; i

cin>>myVec[i];

SortVector(myVec);//call for sorting

cout<<"Output is: ";

for (int i=0; i

cout << myVec[i] << " ";/* your code here */

return 0;

}

main.cpp: In function 'void SortVector(std::vector&)':

main.cpp:7:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?

7 | sort(myVec.begin(), myVec.end()); //sort function to sort from start to end

| ^~~~

| qsort

I'm not sure what this error means and when I went to fix it in my code a whole list of errors came out as well. I'm not sure if my code is at all correct and what needs to be fixed. Much explanation and help needed. Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!