From ef3010bd77d74f78f8364cf88c69885a5df3db7a Mon Sep 17 00:00:00 2001 From: rongyi Date: Wed, 23 Oct 2024 18:49:47 +0800 Subject: [PATCH] idomatic structure rust code, no include macro (#1528) --- codes/rust/chapter_array_and_linkedlist/array.rs | 3 +-- codes/rust/chapter_array_and_linkedlist/linked_list.rs | 4 +--- codes/rust/chapter_array_and_linkedlist/list.rs | 3 +-- codes/rust/chapter_array_and_linkedlist/my_list.rs | 2 +- .../preorder_traversal_i_compact.rs | 4 +--- .../preorder_traversal_ii_compact.rs | 4 +--- .../preorder_traversal_iii_compact.rs | 4 +--- .../preorder_traversal_iii_template.rs | 4 +--- .../space_complexity.rs | 5 +---- .../worst_best_time_complexity.rs | 3 +-- codes/rust/chapter_divide_and_conquer/build_tree.rs | 3 +-- codes/rust/chapter_graph/graph_adjacency_list.rs | 2 +- codes/rust/chapter_hashing/build_in_hash.rs | 3 +-- codes/rust/chapter_hashing/hash_map.rs | 2 +- codes/rust/chapter_heap/heap.rs | 2 +- codes/rust/chapter_heap/my_heap.rs | 2 +- codes/rust/chapter_heap/top_k.rs | 2 +- codes/rust/chapter_searching/hashing_search.rs | 4 +--- codes/rust/chapter_searching/linear_search.rs | 4 +--- codes/rust/chapter_searching/two_sum.rs | 3 +-- codes/rust/chapter_sorting/bubble_sort.rs | 2 +- codes/rust/chapter_sorting/bucket_sort.rs | 2 +- codes/rust/chapter_sorting/counting_sort.rs | 2 +- codes/rust/chapter_sorting/heap_sort.rs | 2 +- codes/rust/chapter_sorting/insertion_sort.rs | 2 +- codes/rust/chapter_sorting/radix_sort.rs | 2 +- codes/rust/chapter_sorting/selection_sort.rs | 2 +- codes/rust/chapter_stack_and_queue/array_deque.rs | 4 +--- codes/rust/chapter_stack_and_queue/array_stack.rs | 2 +- codes/rust/chapter_stack_and_queue/deque.rs | 3 +-- codes/rust/chapter_stack_and_queue/linkedlist_deque.rs | 2 +- codes/rust/chapter_stack_and_queue/linkedlist_queue.rs | 3 +-- codes/rust/chapter_stack_and_queue/linkedlist_stack.rs | 3 +-- codes/rust/chapter_stack_and_queue/queue.rs | 2 +- codes/rust/chapter_stack_and_queue/stack.rs | 2 +- codes/rust/chapter_tree/array_binary_tree.rs | 2 +- codes/rust/chapter_tree/avl_tree.rs | 3 +-- codes/rust/chapter_tree/binary_search_tree.rs | 4 ++-- codes/rust/chapter_tree/binary_tree.rs | 3 +-- codes/rust/chapter_tree/binary_tree_bfs.rs | 4 ++-- codes/rust/chapter_tree/binary_tree_dfs.rs | 4 ++-- codes/rust/{ => src}/include/list_node.rs | 0 codes/rust/{include/include.rs => src/include/mod.rs} | 10 ++++++++-- codes/rust/{ => src}/include/print_util.rs | 8 ++++---- codes/rust/{ => src}/include/tree_node.rs | 0 codes/rust/{ => src}/include/vertex.rs | 0 codes/rust/src/lib.rs | 1 + 47 files changed, 57 insertions(+), 80 deletions(-) rename codes/rust/{ => src}/include/list_node.rs (100%) rename codes/rust/{include/include.rs => src/include/mod.rs} (61%) rename codes/rust/{ => src}/include/print_util.rs (96%) rename codes/rust/{ => src}/include/tree_node.rs (100%) rename codes/rust/{ => src}/include/vertex.rs (100%) create mode 100644 codes/rust/src/lib.rs diff --git a/codes/rust/chapter_array_and_linkedlist/array.rs b/codes/rust/chapter_array_and_linkedlist/array.rs index 5d779e402..2d6870b77 100644 --- a/codes/rust/chapter_array_and_linkedlist/array.rs +++ b/codes/rust/chapter_array_and_linkedlist/array.rs @@ -4,8 +4,7 @@ * Author: xBLACICEx (xBLACKICEx@outlook.com), codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::print_util; use rand::Rng; /* 随机访问元素 */ diff --git a/codes/rust/chapter_array_and_linkedlist/linked_list.rs b/codes/rust/chapter_array_and_linkedlist/linked_list.rs index 8f054f1c2..601a99714 100644 --- a/codes/rust/chapter_array_and_linkedlist/linked_list.rs +++ b/codes/rust/chapter_array_and_linkedlist/linked_list.rs @@ -4,9 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - -use list_node::ListNode; +use hello_algo_rust::include::{print_util, ListNode}; use std::cell::RefCell; use std::rc::Rc; diff --git a/codes/rust/chapter_array_and_linkedlist/list.rs b/codes/rust/chapter_array_and_linkedlist/list.rs index b723489d5..d2f267be3 100644 --- a/codes/rust/chapter_array_and_linkedlist/list.rs +++ b/codes/rust/chapter_array_and_linkedlist/list.rs @@ -3,8 +3,7 @@ * Created Time: 2023-01-18 * Author: xBLACICEx (xBLACKICEx@outlook.com), codingonion (coderonion@gmail.com) */ - -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* Driver Code */ fn main() { diff --git a/codes/rust/chapter_array_and_linkedlist/my_list.rs b/codes/rust/chapter_array_and_linkedlist/my_list.rs index bc9375f34..8575cee53 100644 --- a/codes/rust/chapter_array_and_linkedlist/my_list.rs +++ b/codes/rust/chapter_array_and_linkedlist/my_list.rs @@ -4,7 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 列表类 */ #[allow(dead_code)] diff --git a/codes/rust/chapter_backtracking/preorder_traversal_i_compact.rs b/codes/rust/chapter_backtracking/preorder_traversal_i_compact.rs index 489668760..fc6993952 100644 --- a/codes/rust/chapter_backtracking/preorder_traversal_i_compact.rs +++ b/codes/rust/chapter_backtracking/preorder_traversal_i_compact.rs @@ -4,10 +4,8 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::{print_util, vec_to_tree, TreeNode}; use std::{cell::RefCell, rc::Rc}; -use tree_node::{vec_to_tree, TreeNode}; /* 前序遍历:例题一 */ fn pre_order(res: &mut Vec>>, root: Option<&Rc>>) { diff --git a/codes/rust/chapter_backtracking/preorder_traversal_ii_compact.rs b/codes/rust/chapter_backtracking/preorder_traversal_ii_compact.rs index 3fcda5c11..67ce5aee8 100644 --- a/codes/rust/chapter_backtracking/preorder_traversal_ii_compact.rs +++ b/codes/rust/chapter_backtracking/preorder_traversal_ii_compact.rs @@ -4,10 +4,8 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::{print_util, vec_to_tree, TreeNode}; use std::{cell::RefCell, rc::Rc}; -use tree_node::{vec_to_tree, TreeNode}; /* 前序遍历:例题二 */ fn pre_order( diff --git a/codes/rust/chapter_backtracking/preorder_traversal_iii_compact.rs b/codes/rust/chapter_backtracking/preorder_traversal_iii_compact.rs index db5a27e3b..9e54e66bd 100644 --- a/codes/rust/chapter_backtracking/preorder_traversal_iii_compact.rs +++ b/codes/rust/chapter_backtracking/preorder_traversal_iii_compact.rs @@ -4,10 +4,8 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::{print_util, vec_to_tree, TreeNode}; use std::{cell::RefCell, rc::Rc}; -use tree_node::{vec_to_tree, TreeNode}; /* 前序遍历:例题三 */ fn pre_order( diff --git a/codes/rust/chapter_backtracking/preorder_traversal_iii_template.rs b/codes/rust/chapter_backtracking/preorder_traversal_iii_template.rs index 8be605238..e7681b11b 100644 --- a/codes/rust/chapter_backtracking/preorder_traversal_iii_template.rs +++ b/codes/rust/chapter_backtracking/preorder_traversal_iii_template.rs @@ -4,10 +4,8 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::{print_util, vec_to_tree, TreeNode}; use std::{cell::RefCell, rc::Rc}; -use tree_node::{vec_to_tree, TreeNode}; /* 判断当前状态是否为解 */ fn is_solution(state: &mut Vec>>) -> bool { diff --git a/codes/rust/chapter_computational_complexity/space_complexity.rs b/codes/rust/chapter_computational_complexity/space_complexity.rs index cd41b2b13..d1583fe25 100644 --- a/codes/rust/chapter_computational_complexity/space_complexity.rs +++ b/codes/rust/chapter_computational_complexity/space_complexity.rs @@ -4,13 +4,10 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - -use list_node::ListNode; +use hello_algo_rust::include::{print_util, ListNode, TreeNode}; use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; -use tree_node::TreeNode; /* 函数 */ fn function() -> i32 { diff --git a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs index 20d8ed33c..df776625f 100644 --- a/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/worst_best_time_complexity.rs @@ -4,8 +4,7 @@ * Author: xBLACICEx (xBLACKICEx@outlook.com), codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::print_util; use rand::seq::SliceRandom; use rand::thread_rng; diff --git a/codes/rust/chapter_divide_and_conquer/build_tree.rs b/codes/rust/chapter_divide_and_conquer/build_tree.rs index 2c1df9c60..e13ae641b 100644 --- a/codes/rust/chapter_divide_and_conquer/build_tree.rs +++ b/codes/rust/chapter_divide_and_conquer/build_tree.rs @@ -4,10 +4,9 @@ * Author: codingonion (coderonion@gmail.com) */ +use hello_algo_rust::include::{print_util, TreeNode}; use std::collections::HashMap; use std::{cell::RefCell, rc::Rc}; -include!("../include/include.rs"); -use tree_node::TreeNode; /* 构建二叉树:分治 */ fn dfs( diff --git a/codes/rust/chapter_graph/graph_adjacency_list.rs b/codes/rust/chapter_graph/graph_adjacency_list.rs index 26b0692bc..5e014d10c 100644 --- a/codes/rust/chapter_graph/graph_adjacency_list.rs +++ b/codes/rust/chapter_graph/graph_adjacency_list.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/vertex.rs"); +pub use hello_algo_rust::include::{vals_to_vets, vets_to_vals, Vertex}; use std::collections::HashMap; diff --git a/codes/rust/chapter_hashing/build_in_hash.rs b/codes/rust/chapter_hashing/build_in_hash.rs index 7ea7620bd..456f9791a 100644 --- a/codes/rust/chapter_hashing/build_in_hash.rs +++ b/codes/rust/chapter_hashing/build_in_hash.rs @@ -4,9 +4,8 @@ * Author: WSL0809 (wslzzy@outlook.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::ListNode; -use crate::list_node::ListNode; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/codes/rust/chapter_hashing/hash_map.rs b/codes/rust/chapter_hashing/hash_map.rs index db5b76b52..53200d055 100644 --- a/codes/rust/chapter_hashing/hash_map.rs +++ b/codes/rust/chapter_hashing/hash_map.rs @@ -4,7 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; use std::collections::HashMap; diff --git a/codes/rust/chapter_heap/heap.rs b/codes/rust/chapter_heap/heap.rs index 4c0d9d9dc..ef4f35008 100644 --- a/codes/rust/chapter_heap/heap.rs +++ b/codes/rust/chapter_heap/heap.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; use std::collections::BinaryHeap; diff --git a/codes/rust/chapter_heap/my_heap.rs b/codes/rust/chapter_heap/my_heap.rs index b087c194f..18b67c622 100644 --- a/codes/rust/chapter_heap/my_heap.rs +++ b/codes/rust/chapter_heap/my_heap.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 大顶堆 */ struct MaxHeap { diff --git a/codes/rust/chapter_heap/top_k.rs b/codes/rust/chapter_heap/top_k.rs index fdfdb97cd..d79076147 100644 --- a/codes/rust/chapter_heap/top_k.rs +++ b/codes/rust/chapter_heap/top_k.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; use std::cmp::Reverse; use std::collections::BinaryHeap; diff --git a/codes/rust/chapter_searching/hashing_search.rs b/codes/rust/chapter_searching/hashing_search.rs index 1e41bc0b2..b2229edcf 100644 --- a/codes/rust/chapter_searching/hashing_search.rs +++ b/codes/rust/chapter_searching/hashing_search.rs @@ -4,9 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - -use list_node::ListNode; +use hello_algo_rust::include::ListNode; use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; diff --git a/codes/rust/chapter_searching/linear_search.rs b/codes/rust/chapter_searching/linear_search.rs index 5a0d131d7..25f6547bb 100644 --- a/codes/rust/chapter_searching/linear_search.rs +++ b/codes/rust/chapter_searching/linear_search.rs @@ -4,9 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - -use list_node::ListNode; +use hello_algo_rust::include::ListNode; use std::cell::RefCell; use std::rc::Rc; diff --git a/codes/rust/chapter_searching/two_sum.rs b/codes/rust/chapter_searching/two_sum.rs index 6766db5dc..5f38d372a 100644 --- a/codes/rust/chapter_searching/two_sum.rs +++ b/codes/rust/chapter_searching/two_sum.rs @@ -4,8 +4,7 @@ * Author: xBLACICEx (xBLACKICEx@outlook.com), codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::print_util; use std::collections::HashMap; /* 方法一:暴力枚举 */ diff --git a/codes/rust/chapter_sorting/bubble_sort.rs b/codes/rust/chapter_sorting/bubble_sort.rs index 2557a222f..972eb6902 100644 --- a/codes/rust/chapter_sorting/bubble_sort.rs +++ b/codes/rust/chapter_sorting/bubble_sort.rs @@ -4,7 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 冒泡排序 */ fn bubble_sort(nums: &mut [i32]) { diff --git a/codes/rust/chapter_sorting/bucket_sort.rs b/codes/rust/chapter_sorting/bucket_sort.rs index 02e09abf2..c959559ac 100644 --- a/codes/rust/chapter_sorting/bucket_sort.rs +++ b/codes/rust/chapter_sorting/bucket_sort.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 桶排序 */ fn bucket_sort(nums: &mut [f64]) { diff --git a/codes/rust/chapter_sorting/counting_sort.rs b/codes/rust/chapter_sorting/counting_sort.rs index c6a5d92cd..ed478afb5 100644 --- a/codes/rust/chapter_sorting/counting_sort.rs +++ b/codes/rust/chapter_sorting/counting_sort.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 计数排序 */ // 简单实现,无法用于排序对象 diff --git a/codes/rust/chapter_sorting/heap_sort.rs b/codes/rust/chapter_sorting/heap_sort.rs index 55ab52428..a70c2c8ab 100644 --- a/codes/rust/chapter_sorting/heap_sort.rs +++ b/codes/rust/chapter_sorting/heap_sort.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 堆的长度为 n ,从节点 i 开始,从顶至底堆化 */ fn sift_down(nums: &mut [i32], n: usize, mut i: usize) { diff --git a/codes/rust/chapter_sorting/insertion_sort.rs b/codes/rust/chapter_sorting/insertion_sort.rs index 37b685aaf..8772e7d02 100644 --- a/codes/rust/chapter_sorting/insertion_sort.rs +++ b/codes/rust/chapter_sorting/insertion_sort.rs @@ -4,7 +4,7 @@ * Author: xBLACKICEx (xBLACKICEx@outlook.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 插入排序 */ fn insertion_sort(nums: &mut [i32]) { diff --git a/codes/rust/chapter_sorting/radix_sort.rs b/codes/rust/chapter_sorting/radix_sort.rs index 722826e1e..f213c4273 100644 --- a/codes/rust/chapter_sorting/radix_sort.rs +++ b/codes/rust/chapter_sorting/radix_sort.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */ fn digit(num: i32, exp: i32) -> usize { diff --git a/codes/rust/chapter_sorting/selection_sort.rs b/codes/rust/chapter_sorting/selection_sort.rs index 9b21d9bc1..87265a541 100644 --- a/codes/rust/chapter_sorting/selection_sort.rs +++ b/codes/rust/chapter_sorting/selection_sort.rs @@ -4,7 +4,7 @@ * Author: WSL0809 (wslzzy@outlook.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 选择排序 */ fn selection_sort(nums: &mut [i32]) { diff --git a/codes/rust/chapter_stack_and_queue/array_deque.rs b/codes/rust/chapter_stack_and_queue/array_deque.rs index 8ad4e487d..905c371fb 100644 --- a/codes/rust/chapter_stack_and_queue/array_deque.rs +++ b/codes/rust/chapter_stack_and_queue/array_deque.rs @@ -3,9 +3,7 @@ * Created Time: 2023-03-11 * Author: codingonion (coderonion@gmail.com) */ - -include!("../include/include.rs"); - +use hello_algo_rust::include::print_util; /* 基于环形数组实现的双向队列 */ struct ArrayDeque { nums: Vec, // 用于存储双向队列元素的数组 diff --git a/codes/rust/chapter_stack_and_queue/array_stack.rs b/codes/rust/chapter_stack_and_queue/array_stack.rs index 4aab6dc2b..19c902207 100644 --- a/codes/rust/chapter_stack_and_queue/array_stack.rs +++ b/codes/rust/chapter_stack_and_queue/array_stack.rs @@ -4,7 +4,7 @@ * Author: WSL0809 (wslzzy@outlook.com), codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* 基于数组实现的栈 */ struct ArrayStack { diff --git a/codes/rust/chapter_stack_and_queue/deque.rs b/codes/rust/chapter_stack_and_queue/deque.rs index 486975033..28b3ad38f 100644 --- a/codes/rust/chapter_stack_and_queue/deque.rs +++ b/codes/rust/chapter_stack_and_queue/deque.rs @@ -4,8 +4,7 @@ * Author: codingonion (coderonion@gmail.com), xBLACKICEx (xBLACKICEx@outlook.com) */ -include!("../include/include.rs"); - +use hello_algo_rust::include::print_util; use std::collections::VecDeque; /* Driver Code */ diff --git a/codes/rust/chapter_stack_and_queue/linkedlist_deque.rs b/codes/rust/chapter_stack_and_queue/linkedlist_deque.rs index b181f8ffd..dda3adb61 100644 --- a/codes/rust/chapter_stack_and_queue/linkedlist_deque.rs +++ b/codes/rust/chapter_stack_and_queue/linkedlist_deque.rs @@ -4,7 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; use std::cell::RefCell; use std::rc::Rc; diff --git a/codes/rust/chapter_stack_and_queue/linkedlist_queue.rs b/codes/rust/chapter_stack_and_queue/linkedlist_queue.rs index 1b940a032..ee2f68f32 100644 --- a/codes/rust/chapter_stack_and_queue/linkedlist_queue.rs +++ b/codes/rust/chapter_stack_and_queue/linkedlist_queue.rs @@ -4,9 +4,8 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::{print_util, ListNode}; -use list_node::ListNode; use std::cell::RefCell; use std::rc::Rc; diff --git a/codes/rust/chapter_stack_and_queue/linkedlist_stack.rs b/codes/rust/chapter_stack_and_queue/linkedlist_stack.rs index f2d479ae2..0a96df0e2 100644 --- a/codes/rust/chapter_stack_and_queue/linkedlist_stack.rs +++ b/codes/rust/chapter_stack_and_queue/linkedlist_stack.rs @@ -4,9 +4,8 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::{print_util, ListNode}; -use list_node::ListNode; use std::cell::RefCell; use std::rc::Rc; diff --git a/codes/rust/chapter_stack_and_queue/queue.rs b/codes/rust/chapter_stack_and_queue/queue.rs index 56144666a..e2fd8400c 100644 --- a/codes/rust/chapter_stack_and_queue/queue.rs +++ b/codes/rust/chapter_stack_and_queue/queue.rs @@ -4,7 +4,7 @@ * Author: codingonion (coderonion@gmail.com), xBLACKICEx (xBLACKICEx@outlook.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; use std::collections::VecDeque; diff --git a/codes/rust/chapter_stack_and_queue/stack.rs b/codes/rust/chapter_stack_and_queue/stack.rs index 64e214245..b2df65b5b 100644 --- a/codes/rust/chapter_stack_and_queue/stack.rs +++ b/codes/rust/chapter_stack_and_queue/stack.rs @@ -4,7 +4,7 @@ * Author: codingonion (coderonion@gmail.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; /* Driver Code */ pub fn main() { diff --git a/codes/rust/chapter_tree/array_binary_tree.rs b/codes/rust/chapter_tree/array_binary_tree.rs index 1ce7e9048..98504159b 100644 --- a/codes/rust/chapter_tree/array_binary_tree.rs +++ b/codes/rust/chapter_tree/array_binary_tree.rs @@ -4,7 +4,7 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::{print_util, tree_node}; /* 数组表示下的二叉树类 */ struct ArrayBinaryTree { diff --git a/codes/rust/chapter_tree/avl_tree.rs b/codes/rust/chapter_tree/avl_tree.rs index a48ec813f..faa3787ef 100644 --- a/codes/rust/chapter_tree/avl_tree.rs +++ b/codes/rust/chapter_tree/avl_tree.rs @@ -4,12 +4,11 @@ * Author: night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::{print_util, TreeNode}; use std::cell::RefCell; use std::cmp::Ordering; use std::rc::Rc; -use tree_node::TreeNode; type OptionTreeNodeRc = Option>>; diff --git a/codes/rust/chapter_tree/binary_search_tree.rs b/codes/rust/chapter_tree/binary_search_tree.rs index aca3f4334..21daad9f7 100644 --- a/codes/rust/chapter_tree/binary_search_tree.rs +++ b/codes/rust/chapter_tree/binary_search_tree.rs @@ -4,13 +4,13 @@ * Author: xBLACKICEx (xBLACKICE@outlook.com)、night-cruise (2586447362@qq.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::print_util; use std::cell::RefCell; use std::cmp::Ordering; use std::rc::Rc; -use tree_node::TreeNode; +use hello_algo_rust::include::TreeNode; type OptionTreeNodeRc = Option>>; diff --git a/codes/rust/chapter_tree/binary_tree.rs b/codes/rust/chapter_tree/binary_tree.rs index 823088617..5843845da 100644 --- a/codes/rust/chapter_tree/binary_tree.rs +++ b/codes/rust/chapter_tree/binary_tree.rs @@ -4,8 +4,7 @@ * Author: xBLACKICEx (xBLACKICE@outlook.com) */ use std::rc::Rc; -include!("../include/include.rs"); -use tree_node::TreeNode; +use hello_algo_rust::include::{print_util, TreeNode}; /* Driver Code */ fn main() { diff --git a/codes/rust/chapter_tree/binary_tree_bfs.rs b/codes/rust/chapter_tree/binary_tree_bfs.rs index 572f88351..e50c2df95 100644 --- a/codes/rust/chapter_tree/binary_tree_bfs.rs +++ b/codes/rust/chapter_tree/binary_tree_bfs.rs @@ -4,11 +4,11 @@ * Author: xBLACKICEx (xBLACKICE@outlook.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::{print_util, vec_to_tree, TreeNode}; +use hello_algo_rust::op_vec; use std::collections::VecDeque; use std::{cell::RefCell, rc::Rc}; -use tree_node::{vec_to_tree, TreeNode}; /* 层序遍历 */ fn level_order(root: &Rc>) -> Vec { diff --git a/codes/rust/chapter_tree/binary_tree_dfs.rs b/codes/rust/chapter_tree/binary_tree_dfs.rs index 22f978ff2..56c68614b 100644 --- a/codes/rust/chapter_tree/binary_tree_dfs.rs +++ b/codes/rust/chapter_tree/binary_tree_dfs.rs @@ -4,11 +4,11 @@ * Author: xBLACKICEx (xBLACKICE@outlook.com) */ -include!("../include/include.rs"); +use hello_algo_rust::include::{vec_to_tree, TreeNode, print_util}; +use hello_algo_rust::op_vec; use std::cell::RefCell; use std::rc::Rc; -use tree_node::{vec_to_tree, TreeNode}; /* 前序遍历 */ fn pre_order(root: Option<&Rc>>) -> Vec { diff --git a/codes/rust/include/list_node.rs b/codes/rust/src/include/list_node.rs similarity index 100% rename from codes/rust/include/list_node.rs rename to codes/rust/src/include/list_node.rs diff --git a/codes/rust/include/include.rs b/codes/rust/src/include/mod.rs similarity index 61% rename from codes/rust/include/include.rs rename to codes/rust/src/include/mod.rs index a288d8b50..6cba6f9a5 100644 --- a/codes/rust/include/include.rs +++ b/codes/rust/src/include/mod.rs @@ -4,7 +4,13 @@ * Author: codingonion (coderonion@gmail.com), xBLACKICEx (xBLACKICE@outlook.com) */ -pub mod print_util; pub mod list_node; +pub mod print_util; pub mod tree_node; -pub mod vertex; \ No newline at end of file +pub mod vertex; + +// rexport to include +pub use list_node::*; +pub use print_util::*; +pub use tree_node::*; +pub use vertex::*; diff --git a/codes/rust/include/print_util.rs b/codes/rust/src/include/print_util.rs similarity index 96% rename from codes/rust/include/print_util.rs rename to codes/rust/src/include/print_util.rs index 68b4870a2..eccc659dd 100644 --- a/codes/rust/include/print_util.rs +++ b/codes/rust/src/include/print_util.rs @@ -9,8 +9,8 @@ use std::fmt::Display; use std::collections::{HashMap, VecDeque}; use std::rc::Rc; -use crate::list_node::ListNode; -use crate::tree_node::{TreeNode, vec_to_tree}; +use super::list_node::ListNode; +use super::tree_node::{TreeNode, vec_to_tree}; struct Trunk<'a, 'b> { prev: Option<&'a Trunk<'a, 'b>>, @@ -99,5 +99,5 @@ pub fn print_heap(heap: Vec) { println!("堆的树状表示:"); if let Some(root) = vec_to_tree(heap.into_iter().map(|val| Some(val)).collect()) { print_tree(&root); - } -} \ No newline at end of file + } +} diff --git a/codes/rust/include/tree_node.rs b/codes/rust/src/include/tree_node.rs similarity index 100% rename from codes/rust/include/tree_node.rs rename to codes/rust/src/include/tree_node.rs diff --git a/codes/rust/include/vertex.rs b/codes/rust/src/include/vertex.rs similarity index 100% rename from codes/rust/include/vertex.rs rename to codes/rust/src/include/vertex.rs diff --git a/codes/rust/src/lib.rs b/codes/rust/src/lib.rs new file mode 100644 index 000000000..2883b9104 --- /dev/null +++ b/codes/rust/src/lib.rs @@ -0,0 +1 @@ +pub mod include;