Polish the chapter of array and linkedlist

This commit is contained in:
krahets
2023-08-17 05:13:19 +08:00
parent 0858ab91c0
commit c310edb672
26 changed files with 287 additions and 236 deletions
@@ -8,7 +8,7 @@ include!("../include/include.rs");
use rand::Rng;
/* 随机返回一个数组元素 */
/* 随机访问元素 */
fn random_access(nums: &[i32]) -> i32 {
// 在区间 [0, nums.len()) 中随机抽取一个数字
let random_index = rand::thread_rng().gen_range(0..nums.len());
@@ -12,8 +12,8 @@ use std::cell::RefCell;
/* 双向链表节点 */
pub struct ListNode<T> {
pub val: T, // 节点值
pub next: Option<Rc<RefCell<ListNode<T>>>>, // 后继节点引用(指针
pub prev: Option<Rc<RefCell<ListNode<T>>>>, // 前驱节点引用(指针
pub next: Option<Rc<RefCell<ListNode<T>>>>, // 后继节点指针
pub prev: Option<Rc<RefCell<ListNode<T>>>>, // 前驱节点指针
}
impl<T> ListNode<T> {