/
fluffymax2005
/
algorithms
Обзор
Документация
Войти
/
fluffymax2005
/
algorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
bubble_sort.cpp
41 строка
914 B
fluffymax2005
Init commit for initial algorithms
16 фев 2026, 10:37
16 фев 2026, 10:37
85155db
Код
Авторство
О чём код?
#include <iostream> #include <new> #include <ostream> #include <stdlib.h> template <typename T> class BubbleSort { public: static void sort(T *arr, const size_t length) { for (auto i = 0; i < length - 1; ++i) for (auto j = i + 1; j < length; ++j) { if (arr[i] > arr[j]) { T buf = arr[j]; arr[j] = arr[i]; arr[i] = buf; } } } static T *createArray(const size_t length) { T *arr = new (std::nothrow) T[length]; if (arr) { for (size_t i = 0; i < length; ++i) { arr[i] = rand() % 65536; } } return arr; } static void printArray(T *arr, size_t length, std::ostream &os = std::cout) { if (arr == nullptr || length < 1) return; os << "Arr = ["; for (auto i = 0; i < length; ++i) { if (i == length - 1) os << arr[i] << "]"; else os << arr[i] << ", "; } } };