From 921ca197bf855d17dc2df2faca7f62fb1701b573 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 5 Feb 2024 12:38:25 +0100 Subject: [PATCH] Updated --- src/io.h | 23 +++++++++++++++++++++-- src/main.cpp | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/io.h b/src/io.h index 2ac5eb8..ebe4d8d 100644 --- a/src/io.h +++ b/src/io.h @@ -6,6 +6,24 @@ void write_answer(int x); void convert_char_to_ascii(); void print_type_size_bytes(); +#include +template +struct TypeName +{ + static const char *Get() + { + return typeid(T).name(); + } +}; +template <> +struct TypeName +{ + static const char *Get() + { + return "s"; + } +}; + template void bubble_sort(int size, T *a) { @@ -25,12 +43,13 @@ void bubble_sort(int size, T *a) template void bubble_sort_print(int size, T *a) { - std::cout << "unsorted Array: "; + + std::cout << "unsorted " << TypeName::Get() << " Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; bubble_sort(size, a); - std::cout << "sorted Array: "; + std::cout << "sorted " << TypeName::Get() << " Array: "; for (int i = 0; i < size; i++) std::cout << a[i] << ", "; std::cout << "\n"; diff --git a/src/main.cpp b/src/main.cpp index 9c84a8e..74fc882 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,12 +5,14 @@ int main() { int demo[]{11, 14, 3, 18, 8, 17, 43, 6, 5, 4}; double demo2[]{11.2, 14.3, 3.2, 18.6, 8.7, 17.9, 43.3, 12.3}; + std::string demo3[]{"hallo", "welo", "kekw", "imagin"}; // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); bubble_sort_print(sizeof(demo) / sizeof(demo[0]), demo); bubble_sort_print(sizeof(demo2) / sizeof(demo2[0]), demo2); + bubble_sort_print(sizeof(demo3) / sizeof(demo3[0]), demo3); return 0; }