mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user