-
-
Save Thecarisma/17a0b874805b0f4cebc6380305e2653d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn reverse_string(s: &mut Vec<char>) { | |
if s.len() <= 1 { | |
return; | |
} | |
let mut i = 0; | |
let mut j = s.len() - 1; | |
while i != j && i < j { | |
s.swap(i, j); | |
i += 1; | |
j -= 1; | |
} | |
} | |
fn main() { | |
let mut shit = vec!['H','a','n','n','a','h']; | |
reverse_string(&mut shit); | |
dbg!(shit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment