Fix rust compile warning and an obvious print error in array.rs (#1144)

* Fix rust compile warning and an obvious print error in array.rs

* Update LinkedList

1. drop unnessaray mut borrow
2. fmt code and make variable more readable

* follow convention of this repo

* Update list_node.rs

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
rongyi
2024-03-18 02:44:03 +08:00
committed by GitHub
parent 7b1094318b
commit 6f1ec66949
4 changed files with 15 additions and 18 deletions

View File

@@ -90,7 +90,7 @@ fn main() {
// 长度扩展
let mut nums = extend(nums, 3);
print!("将数组长度扩展至 8 ,得到 nums = ");
print_util::print_array(&arr);
print_util::print_array(&nums);
// 插入元素
insert(&mut nums, 6, 3);

View File

@@ -37,9 +37,10 @@ pub fn access<T>(head: Rc<RefCell<ListNode<T>>>, index: i32) -> Rc<RefCell<ListN
if index <= 0 {
return head;
};
if let Some(node) = &head.borrow_mut().next {
if let Some(node) = &head.borrow().next {
return access(node.clone(), index - 1);
}
return head;
}