Created
November 27, 2014 00:37
-
-
Save kai5263499/5ea926f6cea6a12242d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Permute the string using Heap's algorithm https://en.wikipedia.org/wiki/Heap%27s_algorithm | |
var perm = function(list, n){ | |
if(n==1){ | |
var inputString = list.join(''); | |
console.log(inputString); | |
} else { | |
for(var c=0;c<n;c++){ | |
perm(list,n-1); | |
if(n%2===0){ | |
var temp1=list[c]; | |
list[c]=list[list.length-1]; | |
list[list.length-1]=temp1; | |
}else{ | |
var temp2=list[0]; | |
list[0]=list[list.length-1]; | |
list[list.length-1]=temp2; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment