pub trait Swap3<I = usize> {
// Required methods
fn swap3_bca(&mut self, a: I, b: I, c: I);
fn swap3_cab(&mut self, a: I, b: I, c: I);
}
Expand description
Trait providing the Swap3::swap3_bca
and Swap3::swap3_cab
functions directly.
Required Methods§
sourcefn swap3_bca(&mut self, a: I, b: I, c: I)
fn swap3_bca(&mut self, a: I, b: I, c: I)
Rotates three values to the left.
§Arguments
a
- The first index, to be assigned with the value ofdata[b]
.b
- The second index, to be assigned with the value ofdata[c]
.c
- The third index, to be assigned with the value ofdata[a]
.
§Example
use swap3::prelude::*;
let mut vec = vec![50, 10, 90, 25, 30, 75];
vec.swap3_bca(0, 1, 4);
assert_eq!(vec, &[10, 30, 90, 25, 50, 75]);
sourcefn swap3_cab(&mut self, a: I, b: I, c: I)
fn swap3_cab(&mut self, a: I, b: I, c: I)
Rotates three values to the right.
§Arguments
a
- The first index, to be assigned with the value ofdata[c]
.b
- The second index, to be assigned with the value ofdata[a]
.c
- The third index, to be assigned with the value ofdata[b]
.
§Example
use swap3::prelude::*;
let mut vec = vec![50, 10, 90, 25, 30, 75];
vec.swap3_cab(0, 1, 4);
assert_eq!(vec, &[30, 50, 90, 25, 10, 75]);