Created
August 15, 2023 01:27
-
-
Save orez-/c0a1ec2e0ac8da94b9742f2b453537d8 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
fn into_iter(list: Option<Box<ListNode>>) -> LLIntoIter { | |
LLIntoIter(list) | |
} | |
struct LLIntoIter(Option<Box<ListNode>>); | |
impl Iterator for LLIntoIter { | |
type Item = Box<ListNode>; | |
fn next(&mut self) -> Option<Box<ListNode>> { | |
let mut node = self.0.take()?; | |
self.0 = node.next.take(); | |
Some(node) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment