In C++ We can easily sort a part of an vector By
sort(A.begin()+start,A.begin()+end);
But in Rust I can not find a good method,Can Anyone Help me??
You can call sort() on a mutable slice, such as a section of your vector like this:
fn main() {
let mut v: Vec<u32> = vec![7, 6, 5, 4, 3, 2, 1];
v[2..5].sort();
println!("{:?}", v);
}
(Playground)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With