Skip to content

Instantly share code, notes, and snippets.

@gusdelact
Last active October 20, 2019 18:30
Show Gist options
  • Save gusdelact/93a435b52757dd7fd4492db13bee0d30 to your computer and use it in GitHub Desktop.
Save gusdelact/93a435b52757dd7fd4492db13bee0d30 to your computer and use it in GitHub Desktop.
#[derive(Debug)]
enum Lista<'a> {
Cons { dato: u32, siguiente : &'a Lista<'a> } ,
Nil
}
impl<'a> Lista<'a> {
fn new() -> Lista<'a> {
Lista::Nil
}
fn append(&'a mut self, nuevo: u32)-> Lista<'a> {
Lista::Cons{dato:nuevo, siguiente: self }
}
}
fn main() {
let listaVacia = Lista::Nil;
let mut lista01 = Lista::Cons{dato:1u32, siguiente: &listaVacia};
let lista02 = Lista::Cons{dato:2u32, siguiente: &lista01};
let lista03 = Lista::Cons{dato:3u32, siguiente: &lista02};
println!("{:?}",lista03);
let mut listaB = Lista::new();
let mut listaC= listaB.append(20);
let listaD= listaC.append(30);
println!("{:?}",listaD);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment