Created
August 8, 2017 12:05
-
-
Save akamajoris/5bd2639c74ba1539bc4e9a98ee08380a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import "fmt" | |
func HeapPermutation(a []string, size int) { | |
if size == 1 { | |
fmt.Println(a) | |
} | |
for i := 0; i < size; i++ { | |
HeapPermutation(a, size-1) | |
if size%2 == 1 { | |
a[0], a[size-1] = a[size-1], a[0] | |
} else { | |
a[i], a[size-1] = a[size-1], a[i] | |
} | |
} | |
} | |
func main() { | |
a := []string{"a","b","c"} | |
HeapPermutation(a, len(a)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment