idomatic structure rust code, no include macro (#1528)
Some checks failed
Rust / build (macos-latest) (push) Has been cancelled
Rust / build (ubuntu-latest) (push) Has been cancelled
Rust / build (windows-latest) (push) Has been cancelled

This commit is contained in:
rongyi 2024-10-23 18:49:47 +08:00 committed by GitHub
parent 0c60037e56
commit ef3010bd77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 57 additions and 80 deletions

View file

@ -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;
/* 随机访问元素 */

View file

@ -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;

View file

@ -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() {

View file

@ -4,7 +4,7 @@
* Author: codingonion (coderonion@gmail.com)
*/
include!("../include/include.rs");
use hello_algo_rust::include::print_util;
/* 列表类 */
#[allow(dead_code)]

View file

@ -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<Rc<RefCell<TreeNode>>>, root: Option<&Rc<RefCell<TreeNode>>>) {

View file

@ -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(

View file

@ -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(

View file

@ -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<Rc<RefCell<TreeNode>>>) -> bool {

View file

@ -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 {

View file

@ -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;

View file

@ -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(

View file

@ -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;

View file

@ -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};

View file

@ -4,7 +4,7 @@
* Author: codingonion (coderonion@gmail.com)
*/
include!("../include/include.rs");
use hello_algo_rust::include::print_util;
use std::collections::HashMap;

View file

@ -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;

View file

@ -4,7 +4,7 @@
* Author: night-cruise (2586447362@qq.com)
*/
include!("../include/include.rs");
use hello_algo_rust::include::print_util;
/* 大顶堆 */
struct MaxHeap {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
/* 方法一:暴力枚举 */

View file

@ -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]) {

View file

@ -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]) {

View file

@ -4,7 +4,7 @@
* Author: night-cruise (2586447362@qq.com)
*/
include!("../include/include.rs");
use hello_algo_rust::include::print_util;
/* 计数排序 */
// 简单实现,无法用于排序对象

View file

@ -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) {

View file

@ -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]) {

View file

@ -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 {

View file

@ -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]) {

View file

@ -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<i32>, // 用于存储双向队列元素的数组

View file

@ -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<T> {

View file

@ -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 */

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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() {

View file

@ -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 {

View file

@ -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<Rc<RefCell<TreeNode>>>;

View file

@ -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<Rc<RefCell<TreeNode>>>;

View file

@ -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() {

View file

@ -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<RefCell<TreeNode>>) -> Vec<i32> {

View file

@ -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<RefCell<TreeNode>>>) -> Vec<i32> {

View file

@ -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;
pub mod vertex;
// rexport to include
pub use list_node::*;
pub use print_util::*;
pub use tree_node::*;
pub use vertex::*;

View file

@ -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<i32>) {
println!("堆的树状表示:");
if let Some(root) = vec_to_tree(heap.into_iter().map(|val| Some(val)).collect()) {
print_tree(&root);
}
}
}
}

1
codes/rust/src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod include;