Skip to content

Instantly share code, notes, and snippets.

@swgillespie
Created April 13, 2014 06:32
Show Gist options
  • Save swgillespie/10571707 to your computer and use it in GitHub Desktop.
Save swgillespie/10571707 to your computer and use it in GitHub Desktop.
use std::fmt;
#[deriving(Show, Clone)]
pub enum LinkedList<T> {
Node(T, ~LinkedList<T>),
Nil
}
impl<T: Clone> LinkedList<T> {
pub fn new() -> LinkedList<T> {
Nil
}
pub fn push(self, val: T) -> LinkedList<T> {
self = Node(val, ~self)
}
}
fn main() {
let list: LinkedList<int> = LinkedList::new();
list.push(42);
println!("{}", list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment