Created
April 16, 2014 19:37
-
-
Save samebchase/10924553 to your computer and use it in GitHub Desktop.
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
use std::strbuf::StrBuf; | |
fn reverse_sentence(sentence: ~str) -> ~str { | |
let mut buffer = StrBuf::new(); | |
let mut string_vector: Vec<~str> = Vec::new(); | |
for word in sentence.split(' ') { | |
string_vector.push(word.to_owned()); | |
} | |
for word in string_vector.iter().rev() { | |
buffer.push_str(word.clone()); | |
buffer.push_str(" "); | |
} | |
buffer.into_owned() | |
} | |
fn main() { | |
println!("{}", reverse_sentence(~"This is a sentence containing words")); | |
} | |
// irukandji% ./reverse-sentence | |
// words containing sentence a is This |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment