Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 18:27, 6 December 2016
, 7 years ago→{{header|Rust}}: Added comment explanations
(→{{header|Rust}}: Added Rust) |
m (→{{header|Rust}}: Added comment explanations) |
||
Line 1,943:
assert!(rows != 0 && cols != 0);
// Creates a vector of vectors with all elements initialized to 0.
let mut v =
v[rows-1][cols-1] = 4;
println!("{}", v[rows-1][cols-1]);
Line 1,950 ⟶ 1,951:
}
// Returns a dynamically-allocated array of size `n`,
fn initialize_vec<F,T>(f: F, size: usize) -> Vec<T>▼
// initialized with the values computed by `f`
where F: Fn(usize) -> T▼
{
let mut vec = Vec::with_capacity(
for i in 0..
vec.push(f(
}
vec
|