re-added a lot of the algorithms!
This commit is contained in:
parent
e9d1d8ee2b
commit
0b9d7b5acc
3 changed files with 33 additions and 15 deletions
|
@ -47,10 +47,10 @@ impl Algorithm{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub async fn bubbleSort(length:i32, delay:f32){
|
||||||
pub async fn bubbleSort(length:i32){
|
let mut list = GuiVec::new(screen_width(), screen_height(), length, delay);
|
||||||
let mut list = GuiVec::new(screen_width(), screen_height(), length);
|
|
||||||
list.randomize();
|
list.randomize();
|
||||||
let n = list.len();
|
let n = list.len();
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
|
@ -63,8 +63,8 @@ impl Algorithm{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn bogoSort(length:i32){
|
pub async fn bogoSort(length:i32, delay:f32){
|
||||||
let mut list = GuiVec::new(screen_width(), screen_height(), length);
|
let mut list = GuiVec::new(screen_width(), screen_height(), length, delay);
|
||||||
list.randomize();
|
list.randomize();
|
||||||
loop{
|
loop{
|
||||||
list.draw().await;
|
list.draw().await;
|
||||||
|
@ -75,8 +75,8 @@ impl Algorithm{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cocktailShaker(length:i32){
|
pub async fn cocktailShaker(length:i32, delay:f32){
|
||||||
let mut list = GuiVec::new(screen_width(), screen_height(), length);
|
let mut list = GuiVec::new(screen_width(), screen_height(), length, delay);
|
||||||
list.randomize();
|
list.randomize();
|
||||||
let mut lowerBound = 0;
|
let mut lowerBound = 0;
|
||||||
let mut upperBound = list.len()-1;
|
let mut upperBound = list.len()-1;
|
||||||
|
@ -108,8 +108,8 @@ impl Algorithm{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn binaryHeap(length:i32){
|
pub async fn binaryHeap(length:i32, delay:f32){
|
||||||
let mut list = GuiVec::new(screen_width(), screen_height(), length);
|
let mut list = GuiVec::new(screen_width(), screen_height(), length, delay);
|
||||||
let mut indexMap:HashMap<i32, usize> = HashMap::new();
|
let mut indexMap:HashMap<i32, usize> = HashMap::new();
|
||||||
let mut binHeap:BinaryHeap<i32> = BinaryHeap::new();
|
let mut binHeap:BinaryHeap<i32> = BinaryHeap::new();
|
||||||
list.randomize();
|
list.randomize();
|
||||||
|
@ -130,7 +130,7 @@ impl Algorithm{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,14 +65,16 @@ impl GuiVec{
|
||||||
});
|
});
|
||||||
self.delay = match delayText.parse::<f32>(){
|
self.delay = match delayText.parse::<f32>(){
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(error)=> {1.0}
|
Err(_)=> {f32::MAX}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
next_frame().await;
|
next_frame().await;
|
||||||
if frames >= self.delay{
|
|
||||||
|
if frames >= self.delay/10000.0{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
frames += get_frame_time()*1000.0;
|
frames += get_frame_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -17,7 +17,7 @@ async fn main() {
|
||||||
let mut length = 1;
|
let mut length = 1;
|
||||||
let mut lengthString = "100".to_owned();
|
let mut lengthString = "100".to_owned();
|
||||||
let mut delay = 0.;
|
let mut delay = 0.;
|
||||||
let mut delayText = "0.0".to_owned();
|
let mut delayText = "1".to_owned();
|
||||||
loop{
|
loop{
|
||||||
clear_background(WHITE);
|
clear_background(WHITE);
|
||||||
|
|
||||||
|
@ -38,10 +38,26 @@ async fn main() {
|
||||||
ui.input_text(hash!(), "Length Of Array!", &mut lengthString);
|
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;
|
//State::State::runInsertSort(delay,length).await;
|
||||||
Algorithm::Algorithm::insertSort(length, 1.0).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
|
next_frame().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue