use std::rc::Rc;
use std::cell::RefCell;

struct Node {
    value: i32,
    next: Option<Rc<RefCell<Node>>>,
}

fn main() {
    let node1 = Rc::new(RefCell::new(Node {
        value: 1,
        next: None,
    }));

    let node2 = Rc::new(RefCell::new(Node {
        value: 2,
        next: None,
    }));

    node1.borrow_mut().next = Some(Rc::clone(&node2));

    node2.borrow_mut().value = 42;

    println!("Node 1: {}", node1.borrow().value);
    println!("Node 2: {}", node1.borrow().next.as_ref().unwrap().borrow().value);
}