Skip to content

Polish rust#1777

Merged
krahets merged 4 commits into
krahets:mainfrom
rongyi:main
Jul 9, 2025
Merged

Polish rust#1777
krahets merged 4 commits into
krahets:mainfrom
rongyi:main

Conversation

@rongyi

@rongyi rongyi commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

No description provided.

};
let num = self.arr[index];
// 将将索引 index 之后的元素都向前移动一位
// 将索引 index 之后的元素都向前移动一位

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@@ -13,22 +13,12 @@ fn test_push_max(heap: &mut BinaryHeap<i32>, val: i32) {
println!("\n元素 {} 入堆后", val);
print_util::print_heap(heap.iter().map(|&val| val).collect());
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used function

let mut nums = self.to_array(node.borrow().next.as_ref());
nums.push(node.borrow().val);
return nums;
pub fn to_array(&self) -> Vec<T> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make method signature same as cpp, no extra arg for head

( $( $x:expr ),* ) => {
vec![
$( Option::from($x).map(|x| x) ),*
$(Option::from($x)),*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless map

*/

/* 基于环形数组实现的队列 */
struct ArrayQueue {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make queue generic, same as linkedlist queue


/* 判断队列是否为空 */
pub fn is_empty(&self) -> bool {
return self.size() == 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as cpp

}

/* 入队操作 */
pub fn push(&mut self, num: T, is_front: bool) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper method, no need to export as public API


/* 判断双向队列是否为空 */
pub fn is_empty(&self) -> bool {
return self.size() == 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as CPP

*/
use hello_algo_rust::include::print_util;
/* 基于环形数组实现的双向队列 */
struct ArrayDeque {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make array deque generic

@krahets krahets left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @rongyi !

@krahets krahets added code Code-related polish Decorative detail or feature bug Bug fixes labels Jul 9, 2025
@krahets krahets merged commit b0c147b into krahets:main Jul 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug fixes code Code-related polish Decorative detail or feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants