reverse vec rust
To reverse a vector in Rust, you can use the reverse
method provided by the Vec
type. Here's an example:
fn main() {
let mut vec = vec![1, 2, 3, 4, 5];
vec.reverse();
println!("{:?}", vec);
}
This code creates a vector vec
with the values [1, 2, 3, 4, 5]
, and then calls the reverse
method on it to reverse the order of the elements. Finally, it prints the reversed vector using println!
.
The output of this code will be [5, 4, 3, 2, 1]
, which is the reversed order of the original vector.
Please let me know if you need further assistance!