Updated
This commit is contained in:
parent
3f5945ca8c
commit
921ca197bf
2 changed files with 23 additions and 2 deletions
23
src/io.h
23
src/io.h
|
@ -6,6 +6,24 @@ void write_answer(int x);
|
||||||
void convert_char_to_ascii();
|
void convert_char_to_ascii();
|
||||||
void print_type_size_bytes();
|
void print_type_size_bytes();
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
template <typename T>
|
||||||
|
struct TypeName
|
||||||
|
{
|
||||||
|
static const char *Get()
|
||||||
|
{
|
||||||
|
return typeid(T).name();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct TypeName<std::string>
|
||||||
|
{
|
||||||
|
static const char *Get()
|
||||||
|
{
|
||||||
|
return "s";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void bubble_sort(int size, T *a)
|
void bubble_sort(int size, T *a)
|
||||||
{
|
{
|
||||||
|
@ -25,12 +43,13 @@ void bubble_sort(int size, T *a)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void bubble_sort_print(int size, T *a)
|
void bubble_sort_print(int size, T *a)
|
||||||
{
|
{
|
||||||
std::cout << "unsorted Array: ";
|
|
||||||
|
std::cout << "unsorted " << TypeName<T>::Get() << " Array: ";
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
std::cout << a[i] << ", ";
|
std::cout << a[i] << ", ";
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
bubble_sort(size, a);
|
bubble_sort(size, a);
|
||||||
std::cout << "sorted Array: ";
|
std::cout << "sorted " << TypeName<T>::Get() << " Array: ";
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
std::cout << a[i] << ", ";
|
std::cout << a[i] << ", ";
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
|
|
@ -5,12 +5,14 @@ int main()
|
||||||
{
|
{
|
||||||
int demo[]{11, 14, 3, 18, 8, 17, 43, 6, 5, 4};
|
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};
|
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();
|
// add_two_numbers();
|
||||||
// convert_char_to_ascii();
|
// convert_char_to_ascii();
|
||||||
print_type_size_bytes();
|
print_type_size_bytes();
|
||||||
|
|
||||||
bubble_sort_print(sizeof(demo) / sizeof(demo[0]), demo);
|
bubble_sort_print(sizeof(demo) / sizeof(demo[0]), demo);
|
||||||
bubble_sort_print(sizeof(demo2) / sizeof(demo2[0]), demo2);
|
bubble_sort_print(sizeof(demo2) / sizeof(demo2[0]), demo2);
|
||||||
|
bubble_sort_print(sizeof(demo3) / sizeof(demo3[0]), demo3);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue