java - Permutation of array -


for example have array:

int a[] = new int[]{3,4,6,2,1}; 

i need list of permutations such if 1 this, {3,2,1,4,6}, others must not same. know if length of array n there n! possible combinations. how can algorithm written?

update: thanks, need pseudo code algorithm like:

for(int i=0;i<a.length;i++){     // code here } 

just algorithm. yes, api functions good, not me much.

if you're using c++, can use std::next_permutation algorithm header:

int a[] = {3,4,6,2,1}; int size = sizeof(a)/sizeof(a[0]); std::sort(a, a+size); {   // print a's elements } while(std::next_permutation(a, a+size)); 

Comments

Popular posts from this blog

ios - Is 'init' forbidden as *part* of a variable name? -

angular - Angular2 Router: Cannot find primary outlet to load 'HomeComponent' -

qt - Microsoft FTP Service 451 The parameter is incorrect -