SHARE
TWEET

Untitled

a guest Sep 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct List {
  2.     value: i32,
  3.     next: Option<List>,
  4. }
  5.  
  6. fn print_list(list: &Option<&List>) {
  7.     match list {
  8.         None => {}
  9.         Some(list) => {
  10.             println!("{}", list.value);
  11.             print_list(list.next);
  12.         }
  13.     }
  14. }
  15.  
  16. fn build_and_print_list(iter: &std::slice::Iter<i32>, tail: Option<&List>) {
  17.     match iter.next() {
  18.         None => print_list(&tail),
  19.         Some(value) => {
  20.             build_and_print_list(
  21.                 iter,
  22.                 Some(List {
  23.                     value: value,
  24.                     next: tail,
  25.                 }),
  26.             );
  27.         }
  28.     }
  29. }
  30.  
  31. fn main() {
  32.     let values = [5, 23, 0, 17, 6, 7, 10, 3, 1];
  33.     let  iter = values.iter();
  34.     build_and_print_list(&iter, None);
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top