Created
January 20, 2015 03:02
-
-
Save tioover/e98c6f553af07435b9dd 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
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