Added continuous bracket.
This commit is contained in:
parent
38f0c14ce8
commit
b5f39f294a
4 changed files with 34 additions and 19 deletions
|
@ -5,3 +5,4 @@ authors = ["Jacob VanDomelen <Jacob.Vandome15@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
uuid = { version = "0.7", features = ["serde", "v4"] }
|
26
gemla/src/bracket/mod.rs
Normal file
26
gemla/src/bracket/mod.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
mod tree;
|
||||||
|
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
fn build_tree(h: u32) -> Option<Box<tree::Tree>> {
|
||||||
|
let mut result: Option<Box<tree::Tree>> = None;
|
||||||
|
|
||||||
|
if h != 0 {
|
||||||
|
result = Some(tree::concat_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_bracket() {
|
||||||
|
let mut height = 1;
|
||||||
|
let mut tree: tree::Tree = *build_tree(height).expect("Error getting result from build_tree.");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
println!("=========================================");
|
||||||
|
println!("Running bracket...");
|
||||||
|
println!("{}", tree);
|
||||||
|
height += 1;
|
||||||
|
tree = *tree::concat_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct Tree {
|
pub struct Tree {
|
||||||
val: u32,
|
id: Uuid,
|
||||||
left: Option<Box<Tree>>,
|
left: Option<Box<Tree>>,
|
||||||
right: Option<Box<Tree>>
|
right: Option<Box<Tree>>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn concat_trees(v: u32, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Box<Tree> {
|
pub fn concat_trees(v: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Box<Tree> {
|
||||||
Box::new(Tree {
|
Box::new(Tree {
|
||||||
val: v,
|
id: v,
|
||||||
left: l,
|
left: l,
|
||||||
right: r
|
right: r
|
||||||
})
|
})
|
||||||
|
@ -23,6 +24,6 @@ impl fmt::Display for Tree {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "({} :{}|{})", self.val, node_str(&self.left), node_str(&self.right))
|
write!(f, "({} :{}|{})", self.id, node_str(&self.left), node_str(&self.right))
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,5 @@
|
||||||
mod tree;
|
mod bracket;
|
||||||
|
|
||||||
fn build_tree(h: u32) -> Option<Box<tree::Tree>> {
|
|
||||||
let mut result: Option<Box<tree::Tree>> = None;
|
|
||||||
|
|
||||||
if h != 0 {
|
|
||||||
result = Some(tree::concat_trees(h, build_tree(h - 1), build_tree(h - 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let tree: tree::Tree = *build_tree(25).expect("Error getting result from build tree.");
|
bracket::run_bracket();
|
||||||
|
|
||||||
println!("Resulting tree from build_tree.");
|
|
||||||
println!("{}", tree);
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue