From 9bb6c0a3614571bc6186a981f87e154f0d696127 Mon Sep 17 00:00:00 2001 From: gallant Date: Fri, 23 Sep 2022 06:39:15 -0500 Subject: [PATCH] initial commit --- .gitignore | 2 ++ Cargo.toml | 8 ++++++++ src/lib.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c8f7b09 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "greedy-example" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..45386a3 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,28 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let array: Vec = vec![1,2,3,6,4,5,7,8]; + assert_eq!(find_outlier_and_sort(array), [1,2,3,4,5,6,7,8]); + } +} + +pub fn find_outlier_and_sort(array: Vec) -> Result,()> { + let mut i = 0; + let mut barnie = 0; + for num in array { + if i == 0{ + if num > &array[i+1] { + barnie = num; + } + }else { + if &array[i-1] <= &array[i] <= &array[i+1]{ + continue; + }else if &array[i-1] <= &array[i+1]{ + barnie = num; + } + } + + i = i + 1; + } +}