added Bubblesort

This commit is contained in:
ZennDev1337 2024-02-05 08:39:20 +01:00
parent 79644bad85
commit 7f0548cd69
3 changed files with 32 additions and 2 deletions

View file

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

View file

@ -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();
void print_type_size_bytes();
void bubble_sort(int *a);

View file

@ -1,12 +1,26 @@
#include <iostream> // 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;
}
}