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

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -