From 0b9d7b5acc00aff0465012357b7175b23a0d3971 Mon Sep 17 00:00:00 2001 From: polsevev Date: Sun, 26 Feb 2023 03:16:09 +0100 Subject: [PATCH] re-added a lot of the algorithms! --- src/Algorithm.rs | 20 ++++++++++---------- src/GuiHookVec.rs | 8 +++++--- src/main.rs | 20 ++++++++++++++++++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Algorithm.rs b/src/Algorithm.rs index 26743af..3a91834 100644 --- a/src/Algorithm.rs +++ b/src/Algorithm.rs @@ -47,10 +47,10 @@ impl Algorithm{ } } + */ - - pub async fn bubbleSort(length:i32){ - let mut list = GuiVec::new(screen_width(), screen_height(), length); + pub async fn bubbleSort(length:i32, delay:f32){ + let mut list = GuiVec::new(screen_width(), screen_height(), length, delay); list.randomize(); let n = list.len(); for i in 0..n { @@ -63,8 +63,8 @@ impl Algorithm{ } - pub async fn bogoSort(length:i32){ - let mut list = GuiVec::new(screen_width(), screen_height(), length); + pub async fn bogoSort(length:i32, delay:f32){ + let mut list = GuiVec::new(screen_width(), screen_height(), length, delay); list.randomize(); loop{ list.draw().await; @@ -75,8 +75,8 @@ impl Algorithm{ } } - pub async fn cocktailShaker(length:i32){ - let mut list = GuiVec::new(screen_width(), screen_height(), length); + pub async fn cocktailShaker(length:i32, delay:f32){ + let mut list = GuiVec::new(screen_width(), screen_height(), length, delay); list.randomize(); let mut lowerBound = 0; let mut upperBound = list.len()-1; @@ -108,8 +108,8 @@ impl Algorithm{ } - pub async fn binaryHeap(length:i32){ - let mut list = GuiVec::new(screen_width(), screen_height(), length); + pub async fn binaryHeap(length:i32, delay:f32){ + let mut list = GuiVec::new(screen_width(), screen_height(), length, delay); let mut indexMap:HashMap = HashMap::new(); let mut binHeap:BinaryHeap = BinaryHeap::new(); list.randomize(); @@ -130,7 +130,7 @@ impl Algorithm{ } - */ + diff --git a/src/GuiHookVec.rs b/src/GuiHookVec.rs index 207c8d8..83f46bb 100644 --- a/src/GuiHookVec.rs +++ b/src/GuiHookVec.rs @@ -65,14 +65,16 @@ impl GuiVec{ }); self.delay = match delayText.parse::(){ Ok(a) => a, - Err(error)=> {1.0} + Err(_)=> {f32::MAX} }; + next_frame().await; - if frames >= self.delay{ + + if frames >= self.delay/10000.0{ break; } - frames += get_frame_time()*1000.0; + frames += get_frame_time(); } } diff --git a/src/main.rs b/src/main.rs index 83fb178..d91a0e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ async fn main() { let mut length = 1; let mut lengthString = "100".to_owned(); let mut delay = 0.; - let mut delayText = "0.0".to_owned(); + let mut delayText = "1".to_owned(); loop{ clear_background(WHITE); @@ -38,10 +38,26 @@ async fn main() { ui.input_text(hash!(), "Length Of Array!", &mut lengthString); }); - if root_ui().button(Vec2::new(screen_width()*0.01, 100.), "RUN!"){ + if root_ui().button(Vec2::new(screen_width()*0.01, 100.), "Run InsertSort!"){ //State::State::runInsertSort(delay,length).await; Algorithm::Algorithm::insertSort(length, 1.0).await; } + if root_ui().button(Vec2::new(screen_width()*0.01, 130.), "Run BubbleSort!"){ + //State::State::runInsertSort(delay,length).await; + Algorithm::Algorithm::bubbleSort(length, 1.0).await; + } + if root_ui().button(Vec2::new(screen_width()*0.01, 160.), "Run BinaryHeapSort!"){ + //State::State::runInsertSort(delay,length).await; + Algorithm::Algorithm::binaryHeap(length, 1.0).await; + } + if root_ui().button(Vec2::new(screen_width()*0.01, 190.), "Run CoctailShakerSort!"){ + //State::State::runInsertSort(delay,length).await; + Algorithm::Algorithm::cocktailShaker(length, 1.0).await; + } + if root_ui().button(Vec2::new(screen_width()*0.01, 220.), "Run BogoSort!"){ + //State::State::runInsertSort(delay,length).await; + Algorithm::Algorithm::bogoSort(length, 1.0).await; + } next_frame().await }