not working yet, just for portability
This commit is contained in:
parent
9bb6c0a361
commit
a607158d9b
19
src/lib.rs
19
src/lib.rs
|
@ -1,28 +1,33 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::find_outlier_and_sort;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
let array: Vec<i32> = vec![1,2,3,6,4,5,7,8];
|
let array: Vec<i32> = vec![1,2,3,6,4,5,7,8];
|
||||||
assert_eq!(find_outlier_and_sort(array), [1,2,3,4,5,6,7,8]);
|
assert_eq!(find_outlier_and_sort(array).unwrap(), [1,2,3,4,5,6,7,8]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_outlier_and_sort(array: Vec<i32>) -> Result<Vec<i32>,()> {
|
pub fn find_outlier_and_sort(array: Vec<i32>) -> Result<Vec<i32>,()> {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut barnie = 0;
|
let mut barnie: usize = 0;
|
||||||
for num in array {
|
for num in &array {
|
||||||
if i == 0{
|
if i == 0{
|
||||||
if num > &array[i+1] {
|
if num > &array[i+1] {
|
||||||
barnie = num;
|
barnie = *num as usize;
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
if &array[i-1] <= &array[i] <= &array[i+1]{
|
if (&array[i-1] <= &array[i]) && (&array[i] <= &array[i+1]){
|
||||||
continue;
|
continue;
|
||||||
}else if &array[i-1] <= &array[i+1]{
|
}else if (&array[i-1] <= &array[i+1]){
|
||||||
barnie = num;
|
barnie = *num as usize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
|
println!("{}", barnie);
|
||||||
|
Ok(vec![1,2,3,4,5,6,7,8])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
8
src/main.rs
Normal file
8
src/main.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
mod lib;
|
||||||
|
|
||||||
|
use greedy_example::find_outlier_and_sort;
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
let funk = vec![1,2,3,6,4,5,7,8];
|
||||||
|
find_outlier_and_sort(funk);
|
||||||
|
}
|
Reference in a new issue