Created
January 25, 2012 13:01
-
-
Save cosmo0920/1676159 to your computer and use it in GitHub Desktop.
Rustのpush_vectorを書いてみる
This file contains hidden or 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; | |
fn vec_push(&v: [int], elt: int){ | |
v += [elt]; | |
} | |
fn main() { | |
let v: [int] = []; | |
let vec_size: uint = 0u; | |
vec_push(v,5); | |
vec_push(v,2); | |
vec_push(v,3); | |
vec_push(v,10); | |
vec_push(v,-3); | |
vec_size = vec::len(v);//vectorのサイズを取得 | |
//添字の範囲を気にしないで済むように | |
uint::range(0u,vec_size) {|i| | |
std::io::println(#fmt("%d",v[i])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment