fn add_at_head(&mut self, val: i32) {
        if self.root.is_none() {
            self.root = Some(Box::new(ListNode::new(val)));
            self.len = 1;
        } else {
            let next = self.root.take();
            self.root = Some(Box::new(ListNode { val, next }));
            self.len += 1;
        }
    }
/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */
Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
Add a node of value val before the first element of the linked list . After the insertion the new node will be the first node of the linked list .
fn add_at_head(&mut self, val: i32) {
        if self.root.is_none() {
            self.root = Some(Box::new(ListNode::new(val)));
            self.len = 1;
        } else {
            let next = self.root.take();
            self.root = Some(Box::new(ListNode { val, next }));
            self.len += 1;
        }
    }
fn add_at_head ( & mut self , val : i32 ) { if self . root . is_none ( ) { self . root = Some ( Box :: new ( ListNode :: new ( val ) ) ) ; self . len = 1 ; } else { let next = self . root . take ( ) ; self . root = Some ( Box :: new ( ListNode { val , next } ) ) ; self . len += 1 ; } }
Add a node of value val before the first element of the linked list.
Add a node of value val before the first element of the linked list .
&mut self
val
i32
&mut self
val
i32