1
0

Add old works for Algorithms and Data Structeres

This commit is contained in:
2025-12-04 20:46:45 +02:00
parent 6794e9ca96
commit 6c03e1714f
33 changed files with 1416 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "exam"
version = "0.1.0"
+4
View File
@@ -0,0 +1,4 @@
[package]
name = "exam"
version = "0.1.0"
edition = "2021"
+7
View File
@@ -0,0 +1,7 @@
# Exam
> Algorithm for replacing elements of a one-dimensional list. Implement in pseudocode or your favorite programming language.
Cooked this bad boy during the exam.
+28
View File
@@ -0,0 +1,28 @@
fn replace<T: Clone + PartialEq>(list: &mut [T], find: &T, with: &T, all: bool) {
for element in list.iter_mut() {
if element == find {
*element = with.clone();
if !all {
return;
}
}
}
}
fn main() {
let mut list: Vec<_> = (0..10).map(|x| x % 7).collect();
println!("{list:?}");
let find = 2;
let with = 42;
replace(&mut list, &find, &with, false);
println!("{list:?}");
replace(&mut list, &find, &with, true);
println!("{list:?}");
let mut list = [1, 2, 3, 4, 1, 3, 1, 0, 4];
replace(&mut list, &1, &9, true);
println!("{list:?}");
}