6.11 LAB: Sort a vector
Write 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 int>& 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.
290064 1698536.qx3zqy7

Respuesta :

The sort a vector program is an illustration of functions, loops and vectors or lists.

The main program

The program written in C++, where comments are used to explain each action is as follows:

#include<bits/stdc++.h>

using namespace std;

//This defines the SortVector function

void SortVector(vector <int>& myVec){

   //This sorts the vector elements in ascending order

   sort(myVec.begin(), myVec.end());

   //This iterates through the sorted vector, and print each element

for (auto x : myVec)

 cout << x << " ";

}

//The main begins here

int main(){

   //This declares all the variables

   int num, numInput; vector<int> v;

   //This gets the length of the vector

   cin>>num;

   //The following iteration gets input for the vector

   for(int i = 0; i<num;i++){

       cin>>numInput;

       v.push_back(numInput);

   }

   //This calls the SortVector function

   SortVector(v);

return 0;

}

Read more about functions at:

https://brainly.com/question/24833629

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE