lexicographically_next_permutation

Function lexicographically_next_permutation 

Source
pub fn lexicographically_next_permutation<T: PartialOrd + Copy>(
    a: &mut [T],
) -> bool
Expand description

Generates the lexicographically next permutation of an array / vector.

Returns false if the permutation is the last permutation.

The sequence is modified in place.

ยงExamples

let mut v = ['a', 'b', 'c'];

jabba_lib::jpermutation::lexicographically_next_permutation(&mut v);
assert_eq!(v, ['a', 'c', 'b']);
jabba_lib::jpermutation::lexicographically_next_permutation(&mut v);
assert_eq!(v, ['b', 'a', 'c']);
jabba_lib::jpermutation::lexicographically_next_permutation(&mut v);
assert_eq!(v, ['b', 'c', 'a']);
Examples found in repository?
examples/permutation.rs (line 8)
3fn main() {
4    let mut v = ['c', 'a', 'b', 'e', 'd'];
5    println!("{:?}", v);
6    println!();
7    for _ in 0..3 {
8        jp::lexicographically_next_permutation(&mut v);
9        println!("{:?}", v);
10    }
11
12    println!("---");
13
14    let mut v = ['a', 'b', 'c'];
15    println!("{:?}", v);
16    loop {
17        let status = jp::lexicographically_next_permutation(&mut v);
18        if !status {
19            break;
20        }
21        println!("{:?}", v);
22    }
23}