Created
December 15, 2019 21:38
-
-
Save rust-play/8ceee02bd4213e0744049e079027d40a 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