Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 06:31:38 AM
  • Proudly celebrating 10 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.
  • donate

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

alivingspirit

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 167
    • View Profile
    • Donate to Member
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,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Programming Problem: return every possible order of an array.
« Reply #1 on: March 22, 2009, 07:02:50 PM »
C++, <algorithm>, std::next_permutation ? :)
- carpe noctem

housetier

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

alivingspirit

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