June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,28 +1,15 @@
|
|||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args().skip(1).flat_map(|num| num.parse());
|
||||
let rows = args.next().expect("Expected number of rows as first argument");
|
||||
let cols = args.next().expect("Expected number of columns as second argument");
|
||||
|
||||
assert!(rows != 0 && cols != 0);
|
||||
assert_ne!(rows, 0, "rows were zero");
|
||||
assert_ne!(cols, 0, "cols were zero");
|
||||
|
||||
// Creates a vector of vectors with all elements initialized to 0.
|
||||
let mut v = init_vec(rows, || init_vec(cols, || 0));
|
||||
let mut v = vec![vec![0; cols]; rows];
|
||||
v[0][0] = 1;
|
||||
println!("{}", v[0][0]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Returns a dynamically-allocated array of size `n`,
|
||||
// initialized with the values computed by `f`
|
||||
|
||||
fn init_vec<F,T>(n: usize, f: F) -> Vec<T>
|
||||
where F: Fn() -> T
|
||||
{
|
||||
let mut vec = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
vec.push(f());
|
||||
}
|
||||
vec
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue