September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
29
Task/Permutations/Go/permutations-2.go
Normal file
29
Task/Permutations/Go/permutations-2.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var a = []int{1, 2, 3}
|
||||
fmt.Println(a)
|
||||
var n = len(a) - 1
|
||||
var i, j int
|
||||
for c := 1; c < 6; c++ { // 3! = 6:
|
||||
i = n - 1
|
||||
j = n
|
||||
for a[i] > a[i+1] {
|
||||
i--
|
||||
}
|
||||
for a[j] < a[i] {
|
||||
j--
|
||||
}
|
||||
a[i], a[j] = a[j], a[i]
|
||||
j = n
|
||||
i += 1
|
||||
for i < j {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
i++
|
||||
j--
|
||||
}
|
||||
fmt.Println(a)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue