Last active
December 25, 2015 20:19
-
-
Save JeffBelgum/7034013 to your computer and use it in GitHub Desktop.
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
#[deriving(Clone, Eq)] | |
struct Node<T> { | |
v: T, | |
next: @mut Option<Node<T>> | |
} | |
#[deriving(Clone, Eq)] | |
struct List<T> { | |
priv head: @mut Option<Node<T>> | |
} | |
impl<T: Clone + 'static> List <T>{ | |
pub fn new() -> List<T> { | |
let nl = List { head: @mut None }; | |
nl | |
} | |
pub fn push(&mut self, vv: T) { | |
self.head = match *self.head { | |
Some(ref mut hd) => @mut Some(Node { v: vv.clone(), next: @mut Some(hd.clone()) }), | |
None => @mut Some(Node { v: vv.clone(), next: @mut None }) | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment