Last active
April 30, 2017 20:35
-
-
Save danielrangelmoreira/49aec9d478e216fcd1034957dcc5b126 to your computer and use it in GitHub Desktop.
Non recursive Heap (1963) algorithm
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
package main | |
import "fmt" | |
func generate(n int, a []int64) { | |
var c = make([]int, n) | |
fmt.Println(a) | |
i := 0 | |
for i < n { | |
if c[i] < i { | |
if i%2 == 0 { | |
a[0], a[i] = a[i], a[0] | |
} else { | |
a[c[i]], a[i] = a[i], a[c[i]] | |
} | |
fmt.Println(a) | |
c[i]++ | |
i = 0 | |
} else { | |
c[i] = 0 | |
i++ | |
} | |
} | |
} | |
func main() { | |
var digits = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9} | |
generate(len(digits), digits) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment