|
-
February 6th, 2004, 07:51 AM
#1
Show all the permutation...
Does anyone rember what an Permutation it is... for example if I got n=3 ...
P(3)=3! .... that is not a problem for calculating that... the problem is that I would like to show/display all the posible combination...where n is from 1 .... to how long posible...
Someting like this:
If I got :
n=1 ... to show 1
n=2 ... to show 1,2 ; 2,1
n=3 ... ti show 1,2,3 ; 1,3,2 ; 3,21; 3;1;2 ; 2,1,3; 2;3;1;
.......
-
February 6th, 2004, 09:18 AM
#2
Re: Show all the permutation...
Originally posted by lovelove
... the problem is that I would like to show/display all the posible combination
A combination is not a permutation. A combination is related to a permutation, but is not the same thing.
Code:
#include <algorithm>
#include <iostream>
int main()
{
int array[] = {1,2,3 };
std::cout << array[0] << " " << array[1] << " " << array[2] << std::endl;
while (std::next_permutation(array, array + 3) )
std::cout << array[0] << " " << array[1] << " " << array[2] << std::endl;
}
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|