ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Programming Problem: return every possible order of an array.

(1/1)

alivingspirit:
I'm looking for a simple algorithm that will give me every possible order of an array regardless of size.
For instance: An array of three elements [ 1, 2, 3 ] will give me [ 1, 2, 3 ], [ 1, 3, 2 ], [ 2, 1, 3 ], [ 2, 3, 1 ], [ 3, 1, 2 ] and [ 3, 2, 1 ]. It seems like there should be a pretty simple mathematical solution for this but I can't seem to figure it out or find it anywhere. :(

f0dder:
C++, <algorithm>, std::next_permutation ? :)

housetier:
Wikipedia's page about permutations has example code. I find them quite simple :)

alivingspirit:
Cool. Thanks guys.  :)

Navigation

[0] Message Index

Go to full version