diff --git a/src/io.cpp b/src/io.cpp index 1da65ac..e123476 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -37,4 +37,19 @@ void print_type_size_bytes() std::cout << std::setw(16) << "float:" << sizeof(float) << " bytes\n"; std::cout << std::setw(16) << "double:" << sizeof(double) << " bytes\n"; std::cout << std::setw(16) << "long double:" << sizeof(long double) << " bytes\n"; +} +void bubble_sort(int *a) +{ + for (size_t i = 0; i < 7; i++) + { + for (size_t j = 0; j < 7 - 1 - i; j++) + { + if (a[j] > a[j + 1]) + { + int temp{a[j]}; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } } \ No newline at end of file diff --git a/src/io.h b/src/io.h index 39c803b..e5ae628 100644 --- a/src/io.h +++ b/src/io.h @@ -4,4 +4,5 @@ void add_two_numbers(); int read_number(); void write_answer(int x); void convert_char_to_ascii(); -void print_type_size_bytes(); \ No newline at end of file +void print_type_size_bytes(); +void bubble_sort(int *a); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 40a6f62..da47634 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,26 @@ #include // for std::cout #include "io.h" +#define ARRAY_SIZE 7 + // Definition of function main() +void bubble_sort_demo() +{ + int demo[ARRAY_SIZE]{11, 14, 3, 18, 8, 17, 43}; + for (int i = 0; i < 7; i++) + std::cout << demo[i] << ", "; + std::cout << "\n"; + bubble_sort(demo); + for (int i = 0; i < ARRAY_SIZE; i++) + std::cout << demo[i] << ", "; +} int main() { // add_two_numbers(); // convert_char_to_ascii(); print_type_size_bytes(); + bubble_sort_demo(); + return 0; -} \ No newline at end of file +}