-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
idomatic structure rust code, no include macro (#1528)
- Loading branch information
Showing
47 changed files
with
57 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
* Author: xBLACICEx ([email protected]), codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use hello_algo_rust::include::print_util; | ||
use rand::Rng; | ||
|
||
/* 随机访问元素 */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use list_node::ListNode; | ||
use hello_algo_rust::include::{print_util, ListNode}; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,7 @@ | |
* Created Time: 2023-01-18 | ||
* Author: xBLACICEx ([email protected]), codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* Driver Code */ | ||
fn main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 列表类 */ | ||
#[allow(dead_code)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,8 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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>>>) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,8 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,8 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,8 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,10 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
* Author: xBLACICEx ([email protected]), codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use hello_algo_rust::include::print_util; | ||
use rand::seq::SliceRandom; | ||
use rand::thread_rng; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,9 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/vertex.rs"); | ||
pub use hello_algo_rust::include::{vals_to_vets, vets_to_vals, Vertex}; | ||
|
||
use std::collections::HashMap; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,8 @@ | |
* Author: WSL0809 ([email protected]) | ||
*/ | ||
|
||
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}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
use std::collections::HashMap; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
use std::collections::BinaryHeap; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 大顶堆 */ | ||
struct MaxHeap { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
use std::cmp::Reverse; | ||
use std::collections::BinaryHeap; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use list_node::ListNode; | ||
use hello_algo_rust::include::ListNode; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
* Author: xBLACICEx ([email protected]), codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use hello_algo_rust::include::print_util; | ||
use std::collections::HashMap; | ||
|
||
/* 方法一:暴力枚举 */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 冒泡排序 */ | ||
fn bubble_sort(nums: &mut [i32]) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 桶排序 */ | ||
fn bucket_sort(nums: &mut [f64]) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 计数排序 */ | ||
// 简单实现,无法用于排序对象 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 堆的长度为 n ,从节点 i 开始,从顶至底堆化 */ | ||
fn sift_down(nums: &mut [i32], n: usize, mut i: usize) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: xBLACKICEx ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 插入排序 */ | ||
fn insertion_sort(nums: &mut [i32]) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */ | ||
fn digit(num: i32, exp: i32) -> usize { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: WSL0809 ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 选择排序 */ | ||
fn selection_sort(nums: &mut [i32]) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,7 @@ | |
* Created Time: 2023-03-11 | ||
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use hello_algo_rust::include::print_util; | ||
/* 基于环形数组实现的双向队列 */ | ||
struct ArrayDeque { | ||
nums: Vec<i32>, // 用于存储双向队列元素的数组 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: WSL0809 ([email protected]), codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* 基于数组实现的栈 */ | ||
struct ArrayStack<T> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
* Author: codingonion ([email protected]), xBLACKICEx ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
|
||
use hello_algo_rust::include::print_util; | ||
use std::collections::VecDeque; | ||
|
||
/* Driver Code */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,8 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::{print_util, ListNode}; | ||
|
||
use list_node::ListNode; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,8 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::{print_util, ListNode}; | ||
|
||
use list_node::ListNode; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: codingonion ([email protected]), xBLACKICEx ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
use std::collections::VecDeque; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: codingonion ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::print_util; | ||
|
||
/* Driver Code */ | ||
pub fn main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
include!("../include/include.rs"); | ||
use hello_algo_rust::include::{print_util, tree_node}; | ||
|
||
/* 数组表示下的二叉树类 */ | ||
struct ArrayBinaryTree { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,11 @@ | |
* Author: night-cruise ([email protected]) | ||
*/ | ||
|
||
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>>>; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ | |
* Author: xBLACKICEx ([email protected])、night-cruise ([email protected]) | ||
*/ | ||
|
||
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>>>; | ||
|
||
|
Oops, something went wrong.