Skip to content

Instantly share code, notes, and snippets.

@JeffBelgum
Last active December 25, 2015 20:19
Show Gist options
  • Save JeffBelgum/7034013 to your computer and use it in GitHub Desktop.
Save JeffBelgum/7034013 to your computer and use it in GitHub Desktop.
#[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