first sorting fkt
This commit is contained in:
commit
b83311a93f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "sorting"
|
||||
version = "0.1.0"
|
||||
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "sorting"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
22
src/main.rs
Normal file
22
src/main.rs
Normal file
@ -0,0 +1,22 @@
|
||||
pub fn selection_sort(input: &mut Vec<i32>) {
|
||||
let list_len = input.len();
|
||||
|
||||
for i in 0..list_len - 1 {
|
||||
let mut min = i;
|
||||
for j in i + 1..list_len {
|
||||
if input[j] < input[min] {
|
||||
min = j;
|
||||
}
|
||||
}
|
||||
|
||||
if i != min {
|
||||
input.swap(i, min);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut foo = vec![4, 2, 6, 121, 6, 31, 4, 3];
|
||||
selection_sort(&mut foo);
|
||||
println!("{:?}", foo);
|
||||
}
|
||||
16
src/selection_sort.rs
Normal file
16
src/selection_sort.rs
Normal file
@ -0,0 +1,16 @@
|
||||
pub fn selection_sort(input: &mut Vec<i32>) {
|
||||
let list_len = input.len();
|
||||
|
||||
for i in 0..list_len - 1 {
|
||||
let mut min = i;
|
||||
for j in i + 1..list_len {
|
||||
if input[j] < input[min] {
|
||||
min = j;
|
||||
}
|
||||
}
|
||||
|
||||
if i != min {
|
||||
input.swap(i, min);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user