mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
build(deps): update latest
This commit is contained in:
7
challenges/sorting-algorithms/solutions/rust/bubble-sort/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/bubble-sort/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,25 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
bubble_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bubble_sort<T: Ord>(array: &mut [T]) {
|
||||
for index1 in 0..array.len() {
|
||||
for index2 in 0..array.len() - 1 - index1 {
|
||||
if array[index2] > array[index2 + 1] {
|
||||
array.swap(index2, index2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
bubble_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bubble_sort<T: Ord>(array: &mut [T]) {
|
||||
for index1 in 0..array.len() {
|
||||
for index2 in 0..array.len() - 1 - index1 {
|
||||
if array[index2] > array[index2 + 1] {
|
||||
array.swap(index2, index2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
challenges/sorting-algorithms/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/function/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,15 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
numbers.sort();
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
numbers.sort();
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
7
challenges/sorting-algorithms/solutions/rust/insertion-sort/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/insertion-sort/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,25 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
insertion_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insertion_sort<T: Ord>(array: &mut [T]) {
|
||||
for index in 1..array.len() {
|
||||
let mut index2 = index;
|
||||
while index2 > 0 && array[index2] < array[index2 - 1] {
|
||||
array.swap(index2, index2 - 1);
|
||||
index2 -= 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
insertion_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insertion_sort<T: Ord>(array: &mut [T]) {
|
||||
for index in 1..array.len() {
|
||||
let mut index2 = index;
|
||||
while index2 > 0 && array[index2] < array[index2 - 1] {
|
||||
array.swap(index2, index2 - 1);
|
||||
index2 -= 1;
|
||||
}
|
||||
}
|
||||
}
|
7
challenges/sorting-algorithms/solutions/rust/merge-sort/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/merge-sort/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,52 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
merge_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_sort(array: &mut Vec<i64>) {
|
||||
if array.len() > 1 {
|
||||
let mid = array.len() / 2;
|
||||
let mut left = array[..mid].to_vec();
|
||||
let mut right = array[mid..].to_vec();
|
||||
merge_sort(&mut left);
|
||||
merge_sort(&mut right);
|
||||
merge(left, right, array);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(left: Vec<i64>, right: Vec<i64>, array: &mut Vec<i64>) {
|
||||
let mut left_index = 0;
|
||||
let mut right_index = 0;
|
||||
let mut array_index = 0;
|
||||
while left_index < left.len() && right_index < right.len() {
|
||||
if left[left_index] <= right[right_index] {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
} else {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
}
|
||||
array_index += 1;
|
||||
}
|
||||
while left_index < left.len() {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
while right_index < right.len() {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
merge_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_sort(array: &mut Vec<i64>) {
|
||||
if array.len() > 1 {
|
||||
let mid = array.len() / 2;
|
||||
let mut left = array[..mid].to_vec();
|
||||
let mut right = array[mid..].to_vec();
|
||||
merge_sort(&mut left);
|
||||
merge_sort(&mut right);
|
||||
merge(left, right, array);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(left: Vec<i64>, right: Vec<i64>, array: &mut Vec<i64>) {
|
||||
let mut left_index = 0;
|
||||
let mut right_index = 0;
|
||||
let mut array_index = 0;
|
||||
while left_index < left.len() && right_index < right.len() {
|
||||
if left[left_index] <= right[right_index] {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
} else {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
}
|
||||
array_index += 1;
|
||||
}
|
||||
while left_index < left.len() {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
while right_index < right.len() {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user