Created
January 25, 2017 22:20
-
-
Save kberov/bd1b0625873d1da0c10a90c3d4ea823f 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
fn largest<T: PartialOrd + Copy>(vec: &Vec<T>) -> T { | |
let mut largest = vec[0]; | |
for e in vec { | |
if e > &largest { | |
largest = *e; | |
} | |
} | |
largest | |
} | |
fn main() { | |
let ints = vec![1, 5, 3, 6, 123, 43, 234, 12, 45]; | |
let floats = vec![1.3, 4.2, 3.4, 5.1, 3.0, 9.1, 3.6]; | |
println!("The largest integer is {}!", largest(&ints)); | |
println!("The largest float is {}!", largest(&floats)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment