Source File
permute.go
Belonging Package
modernc.org/mathutil
// Copyright (c) 2014 The mathutil Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package mathutil // import "modernc.org/mathutil"import ()// PermutationFirst generates the first permutation of data.func ( sort.Interface) {sort.Sort()}// PermutationNext generates the next permutation of data if possible and// return true. Return false if there is no more permutation left. Based on// the algorithm described here:// http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_orderfunc ( sort.Interface) bool {var , intfor = .Len() - 2; ; -- { // 1.if < 0 {return false}if .Less(, +1) {break}}for = .Len() - 1; !.Less(, ); -- { // 2.}.Swap(, ) // 3.for , := +1, .Len()-1; < ; ++ { // 4..Swap(, )--}return true}
![]() |
The pages are generated with Golds v0.3.6. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |