This program should generate all permutations of 3 numbers, as inputted by a user. It works fine if I put the numbers in ascending order (1,3,5 for example), but if the user enters the numbers out of order (1,5,3), it does not generate all permutations.
Here is my code:
[code=c++]
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <stdlib.h>
using namespace std;
int main()
{
int x, y, z;
cout << "List three distinct interval classes: " << endl;
cin >> x >> y >> z; // get three numbers from user
cout << "Your numbers are " << x << ' ' << y << " and " << z << endl; // just for confirmation
This is going to be a problem for me, unfortunately. Is there an easy way that I can have the program "sort" the input before it puts it in the vector?
Not unless it's stored in a container...fortunately, a vector is one such container. Just sort it before finding the permutations. If you need to retain the initial order of the elements, you could create a copy of the vector to operate on.