Skip to content

Instantly share code, notes, and snippets.

@cosmo0920
Created January 25, 2012 13:01
Show Gist options
  • Save cosmo0920/1676159 to your computer and use it in GitHub Desktop.
Save cosmo0920/1676159 to your computer and use it in GitHub Desktop.
Rustのpush_vectorを書いてみる
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