In: Computer Science
C++
Have the user type in 10 numbers. Then, using STL STACKs print a table showing each number followed by the next large number. For example, if the user types the following
7 5 12 25
The output should be this:
Element Next Greater Number 5 --> 7 7 --> 12 12 --> 25 25 --> -1
You can use this functor to sort the vector:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct greater
{
template<class T>
bool operator()(T const &a, T const &b) const { return a
> b; }
};
int main()
{
vector <int> v = { 1,4,2,6 };
sort(v.begin(), v.end(), greater());
return 0;
}