fn delete_at_index(&mut self, index: i32) {
        if index < 0 || index >= self.len as i32 {
            eprintln!("invalid index :{}", index);
            return;
        }

        if index == 0 {
            let mut current = &mut self.root;
            if current.is_some() {
                *current = current.as_mut().unwrap().next.take();
                self.len -= 1;
            }
        }

        // 遍历到 index - 1的位置，则删除index位置的元素，并将index+1位置以后的元素添加到当前元素的后面
        let mut current_index = 0;
        let mut current = &mut self.root;
        while current.is_some() {
            if current_index == index - 1 {
                let next_next = current.as_mut().unwrap().next.as_mut().unwrap().next.take();
                current.as_mut().unwrap().next = next_next;
                self.len -= 1;
                break;
            }
            current_index += 1;
            current = &mut current.as_deref_mut().unwrap().next;
        }
    }
/** Delete the index-th node in the linked list, if the index is valid. */
Delete the index-th node in the linked list, if the index is valid.
Delete the index - th node in the linked list if the index is valid .
fn delete_at_index(&mut self, index: i32) {
        if index < 0 || index >= self.len as i32 {
            eprintln!("invalid index :{}", index);
            return;
        }
        if index == 0 {
            let mut current = &mut self.root;
            if current.is_some() {
                *current = current.as_mut().unwrap().next.take();
                self.len -= 1;
            }
        }
        // 遍历到 index - 1的位置，则删除index位置的元素，并将index+1位置以后的元素添加到当前元素的后面
        let mut current_index = 0;
        let mut current = &mut self.root;
        while current.is_some() {
            if current_index == index - 1 {
                let next_next = current.as_mut().unwrap().next.as_mut().unwrap().next.take();
                current.as_mut().unwrap().next = next_next;
                self.len -= 1;
                break;
            }
            current_index += 1;
            current = &mut current.as_deref_mut().unwrap().next;
        }
    }
fn delete_at_index ( & mut self , index : i32 ) { if index < 0 || index >= self . len as i32 { eprintln ! ( " " index ) ; return ; } if index == 0 { let mut current = & mut self . root ; if current . is_some ( ) { * current = current . as_mut ( ) . unwrap ( ) . next . take ( ) ; self . len -= 1 ; } } // 遍历到 index - 1的位置，则删除index位置的元素，并将index+1位置以后的元素添加到当前元素的后面 let mut current_index = 0 ; let mut current = & mut self . root ; while current . is_some ( ) { if current_index == index - 1 { let next_next = current . as_mut ( ) . unwrap ( ) . next . as_mut ( ) . unwrap ( ) . next . take ( ) ; current . as_mut ( ) . unwrap ( ) . next = next_next ; self . len -= 1 ; break ; } current_index += 1 ; current = & mut current . as_deref_mut ( ) . unwrap ( ) . next ; } }
Delete the index-th node in the linked list, if the index is valid.
Delete the index - th node in the linked list if the index is valid .
&mut self
index
i32
&mut self
index
i32