Created
February 3, 2016 03:44
-
-
Save xudifsd/73a4489e14e9b32359fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct ListNode<'a, T> where T: PartialOrd + 'a { | |
val: &'a T, | |
next: Option<Box<ListNode<'a, T>>>, | |
} | |
fn reverse_list<'a, T>(head: Option<Box<ListNode<'a, T>>>) -> Option<Box<ListNode<'a, T>>> | |
where T: 'a + PartialOrd { | |
if let Some(mut p) = head { | |
let mut tail = None; | |
loop { | |
let p_next = p.next.take(); | |
p.next = tail; | |
tail = Some(p); | |
match p_next { | |
None => break, | |
_ => p = p_next.unwrap(), | |
}; | |
}; | |
tail | |
} else { | |
None | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment