use std::rc::Rc;

enum List {
  Node(i32, Rc<List>),
  Tail,
}

use List::{Node, Tail};

fn main() {
    let list_1 = Rc::new(Node(100,
        Rc::new(Node(110,
            Rc::new(Tail)
        ))
    ));
    let list_2 = Node(200, Rc::clone(&list_1));
    let list_3 = Node(300, Rc::clone(&list_1));

    fn print_list(list: &List) {
        println!("List----------");
        let mut l = list;
        loop {
            match &*l {
                Node(value, next) => {
                    println!("Node: {value}");
                    l = next;
                },
                Tail => {
                    println!("Tail");
                    break;
                },
            }
        }
    }

    print_list(&list_2);
    print_list(&list_3);
}
