Did you miss your activation email?

• Friday May 29, 2020, 4:23 pm
• Proudly celebrating 15+ years online.
• Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.

### Author Topic: Programming Problem: return every possible order of an array.  (Read 3183 times)

#### alivingspirit

• Supporting Member
• Joined in 2006
• Posts: 167
##### Programming Problem: return every possible order of an array.
« on: March 22, 2009, 06:09 PM »
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

• Charter Honorary Member
• Joined in 2005
• Posts: 9,146
• [Well, THAT escalated quickly!]
##### Re: Programming Problem: return every possible order of an array.
« Reply #1 on: March 22, 2009, 07:02 PM »
C++, <algorithm>, std::next_permutation ?
- carpe noctem

#### housetier

• Charter Honorary Member
• Joined in 2005
• Posts: 1,321
##### Re: Programming Problem: return every possible order of an array.
« Reply #2 on: March 22, 2009, 07:04 PM »
Wikipedia's page about permutations has example code. I find them quite simple

#### alivingspirit

• Supporting Member
• Joined in 2006
• Posts: 167
##### Re: Programming Problem: return every possible order of an array.
« Reply #3 on: March 22, 2009, 07:14 PM »
Cool. Thanks guys.