ok so far i got this!!! but what i realized is that when i run the ouput 1 2 3 4 5 it gives me the correct output but if i put the value as 3 6 7 8 4 !!! it arranges the number as 3 4 6 7 8 in the ascending order!! i want the next permutatioin to be like
3 6 7 8 4
3 6 8 4 7
3 6 8 7 4
and so on .... plz help me out!!tell me where i am doing wrong ?or can anyone help me to do without defnining 5 number!!! or asking user to enter as many number as they want and giving the next permutation!! thank you
#include <iostream>
#include <algorithm>
#include <iomanip>
#define s 5
using namespace std;

int main () {
double g;
cout << "Input "<<s<<" Numbers : ";

int per[s];
for (int i=0; i<s; i++)
{
cin>>per;
}
int size = sizeof per/sizeof(int);

sort (per,per+size);

do {
for (int i=0; i<size; i++)
{
cout << per << " ";
}
cout<<endl;
} while ( next_permutation (per,per+size) );

return 0;
}

What happens if you remove your call to sort?

thank you very much!!! dindn't realize it was that easy!!it worked!! but is there any way you could help me do that without using standard library!! have been trying hard!! is there a way to make this work without defining specific number!! like taking any number user has inputted and showing the next permutation!!!!can it be doen with using swap and inverse method ? plz help me!! my professor wants me to create using own alogrithm and gave us hint to use swap method!! but m not really able to do it!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.