bubblesort_ifyer/
lib.rs

1/// Sorts stuff_to_sort using the bubblesort algorithom and returns it
2/// Behaviur with nan and and infinity and negative 0 is undefined
3/// Behaviour when version != 1 && version != 255 && version != 254 is undefined
4/// Recursiveness decicides how efficent the program is with 0 being the most efficent. However currently recursiveness must be None.
5use sorted_ifyer::is_sorted;
6pub fn bubblesort<T: std::clone::Clone + std::cmp::PartialOrd>(
7    stuff_to_sort: &[T],
8    version: u128,
9    recursiveness: u128,
10) -> Vec<T> {
11    if version != 1 && version != 255 && version != 254 {
12        panic!("28990985 version not supported")
13    }
14    let mut sorted_stuff = stuff_to_sort.to_vec();
15    if sorted_stuff.is_empty() {
16        return sorted_stuff;
17    }
18    let mut lowest_sorted = stuff_to_sort.len() - 1;
19    while !is_sorted(stuff_to_sort, lowest_sorted + 1, recursiveness, 0) {
20        for i in 1..=lowest_sorted {
21            if sorted_stuff[i - 1] > sorted_stuff[i] {
22                sorted_stuff.swap(i - 1, i);
23            }
24            if i == lowest_sorted {
25                lowest_sorted -= 1
26            }
27        }
28    }
29    sorted_stuff
30}