Question

In: Computer Science

In basic C++ Create a function that takes in a vector, sorts it, then outputs to...

In basic C++

Create a function that takes in a vector, sorts it, then outputs to the console the result.

Solutions

Expert Solution

#include <bits/stdc++.h>

using namespace std;

void order(vector<int> v)

{

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

    cout << "Elements in increasing order is:\n";

    for (int i = 0; i < v.size(); i++)

        cout << v[i] << " ";

}

int main()

{

    int n, i, p;

    cout << "Enter the size of the vector ";

    cin >> n;

    vector<int> v;

    for (i = 0; i < n; i++)

    {

        cin >> p;

        v.push_back(p);

    }

    order(v);

}

PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION


Related Solutions

I am trying to create a function in JAVA that takes in an ArrayList and sorts...
I am trying to create a function in JAVA that takes in an ArrayList and sorts the values by their distance in miles in increasing order. So the closest (or lowest) value would be first. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. The code for the main class is not necessary. I am only really asking for the...
Create a function that takes a vector of vectors as an argument. Each inner vector has...
Create a function that takes a vector of vectors as an argument. Each inner vector has 2 elements. The first element is the numerator and the second element is the denominator. Return the sum of the fractions rounded to the nearest whole number. Examples: sum_fractions({{18, 13}, {4, 5}}) ➞ 2 sum_fractions({{36, 4}, {22, 60}}) ➞ 9 sum_fractions({{11, 2}, {3, 4}, {5, 4}, {21, 11}, {12, 6}}) ➞ 11 Notes Your result should be a number not string. Code in C++...
8) Sorting - C++ You have this function that sorts any vector of char data: void...
8) Sorting - C++ You have this function that sorts any vector of char data: void good_bubble(vector<char> & data, vector<char>::size_type start, vector<char>::size_type end) { vector<char>::size_type loop{0}, cur; bool done{false}; while (loop <= end-start+1 && !done) { done = true; for (cur = start; cur <= end-1-loop; ++cur) { if (data[cur] > data[cur+1]) { swap(data[cur], data[cur+1]); done = false; } } ++loop; } return; } But now you have to sort Date objects! As luck would have it, the Date class...
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance.
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance. Use the following file:...
I am trying to create a method in JAVA that takes in an ArrayList and sorts...
I am trying to create a method in JAVA that takes in an ArrayList and sorts it by the requested "amenities" that a property has. So if someone wants a "pool" and "gym" it would show all members of the array that contain a "pool" and "gym". It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. You can edit it...
Im trying to create a function in C where it takes an array and size and...
Im trying to create a function in C where it takes an array and size and returns the largest absolute value in the array (either negative or positive) using only stdio.h. Any help would be greatly appreciated! Ex: if the array is { -2.5, -10.1, 5.2, 7.0}, it should return -10.1 Ex: if the array is {5.1, 2.3, 4.9, 1.0}, it should return 5.1. double getMaxAbsolute(double array[], int size) {     double max = array[0];    double abs[size];    for...
Create a function output() in C that takes the pointer to the array and its size...
Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (function prototype : void output(int *arrayPtr, int size);
I am trying to create a method in JAVA that takes in an ArrayList<Property> and sorts...
I am trying to create a method in JAVA that takes in an ArrayList<Property> and sorts it by the amount of "reviews" that a property has in increasing order. So the most reviews first. So each listing in the array would contain a different number of reviews, and they should be sorted based on that value. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT