// 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_order
func ( sort.Interface) bool {
	var ,  int
	for  = .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
}