Created
February 11, 2019 07:54
-
-
Save rust-play/e54d15602fa8a1d8f7a17521f85d1133 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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 main() { | |
println!("Hello, world!"); | |
} | |
struct Stack{ | |
length:u32, | |
list:Option<Box<List>>, | |
} | |
struct List{ | |
value:i32, | |
next:Option<Box<List>>, | |
} | |
impl Stack{ | |
fn new()->Self{ | |
Stack{ | |
length:0, | |
list:None, | |
} | |
} | |
fn push(&mut self,value:i32){ | |
let new_list=Box::new( | |
List{ | |
value:value, | |
next:self.list, | |
} | |
); | |
self.list=Some(new_list); | |
self.length=self.length+1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment