1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-10-29 22:17:23 +01:00

feat(solutions): add sorting-algorithms/rust/bubble-sort

This commit is contained in:
Divlo 2022-03-08 09:48:57 +01:00
parent 696de1580d
commit 6d12750ea1
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
5 changed files with 373 additions and 371 deletions

View File

@ -0,0 +1,3 @@
# sorting-algorithms/rust/bubble-sort
Created by [@Divlo](https://github.com/Divlo) on 8 March 2022.

View File

@ -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);
}
}
}
}

699
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -38,17 +38,18 @@
"@commitlint/cli": "16.2.1", "@commitlint/cli": "16.2.1",
"@commitlint/config-conventional": "16.2.1", "@commitlint/config-conventional": "16.2.1",
"@swc/cli": "0.1.55", "@swc/cli": "0.1.55",
"@swc/core": "1.2.143", "@swc/core": "1.2.151",
"@swc/jest": "0.2.17", "@swc/jest": "0.2.20",
"@types/date-and-time": "0.13.0", "@types/date-and-time": "0.13.0",
"@types/jest": "27.4.0", "@types/jest": "27.4.1",
"@types/mock-fs": "4.13.1", "@types/mock-fs": "4.13.1",
"@types/ms": "0.7.31", "@types/ms": "0.7.31",
"@types/node": "17.0.18", "@types/node": "17.0.21",
"@types/validate-npm-package-name": "3.0.3", "@types/validate-npm-package-name": "3.0.3",
"@typescript-eslint/eslint-plugin": "5.14.0",
"editorconfig-checker": "4.0.2", "editorconfig-checker": "4.0.2",
"eslint": "8.9.0", "eslint": "8.10.0",
"eslint-config-conventions": "1.0.1", "eslint-config-conventions": "1.1.0",
"eslint-plugin-import": "2.25.4", "eslint-plugin-import": "2.25.4",
"eslint-plugin-promise": "6.0.0", "eslint-plugin-promise": "6.0.0",
"eslint-plugin-unicorn": "41.0.0", "eslint-plugin-unicorn": "41.0.0",
@ -60,6 +61,6 @@
"mock-fs": "5.1.2", "mock-fs": "5.1.2",
"ms": "2.1.3", "ms": "2.1.3",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"typescript": "4.5.5" "typescript": "4.6.2"
} }
} }

View File

@ -1,4 +1,4 @@
FROM rust:1.58.1 FROM rust:1.59.0
COPY ./ ./ COPY ./ ./
RUN rustc solution.rs RUN rustc solution.rs
CMD ["./solution"] CMD ["./solution"]