Skip to content

Instantly share code, notes, and snippets.

@tioover
Created January 20, 2015 03:02
Show Gist options
  • Save tioover/e98c6f553af07435b9dd to your computer and use it in GitHub Desktop.
Save tioover/e98c6f553af07435b9dd to your computer and use it in GitHub Desktop.
use std::ops::DerefMut;
use std::ops::Deref;
#[derive(Show)]
struct List<T> {
car: T,
cdr: Option<Box<List<T>>>,
}
fn main() {
let mut head = Box::new(List {car: 0i8, cdr: None});
for i in range(1, 42i8) {
head = Box::new(List {car: i, cdr: Some(head)})
}
{
let delete = 8;
let mut now = head.deref_mut();
loop {
let mut temp = now;
if temp.cdr.is_none() {break};
if temp.cdr.as_mut().unwrap().car == delete {
let x = temp.cdr.take();
temp.cdr = x.unwrap().cdr;
break
}
now = temp.cdr.as_mut().unwrap().deref_mut();
}
}
println!("{:?}", head)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment