[][src]Trait algonium::util::Permutation

pub trait Permutation {
    fn next_permutation(&mut self) -> bool;
fn prev_permutation(&mut self) -> bool; }

It contains same methods as std::next_permutaion in C++. these methods should rearrange the elements into the next/prev lexicographically greater permutation.

This is implemented in [T] where T is Ord.

Examples

use algonium::util::Permutation;

let mut perm = [5, 0, 9, 2];
assert!(perm.next_permutation());
assert_eq!(perm, [5, 2, 0, 9]);
assert!(perm.next_permutation());
assert_eq!(perm, [5, 2, 9, 0]);
assert!(perm.prev_permutation());
assert_eq!(perm, [5, 2, 0, 9]);

let mut perm = [4, 3, 2, 1, 0];
assert!(!perm.next_permutation());
assert_eq!(perm, [4, 3, 2, 1, 0]);

Required methods

fn next_permutation(&mut self) -> bool

It rearranges the elements into the next lexicographically greater permutation.

Returns false without modifying any state only if current is the last permutation.

fn prev_permutation(&mut self) -> bool

It rearranges the elements into the previous lexicographically greater permutation.

Returns false without modifying any state only if current is the first permutation.

Loading content...

Implementations on Foreign Types

impl<T> Permutation for [T] where
    T: Ord
[src]

Loading content...

Implementors

Loading content...