AlgoPlus v0.1.0
Loading...
Searching...
No Matches
bubble_sort.h
1#ifndef BUBBLE_SORT_H
2#define BUBBLE_SORT_H
3
4#ifdef __cplusplus
5#include <cstdint>
6#include <iostream>
7#include <vector>
8#endif
9
14template <typename T> void bubble_sort(std::vector<T>& arr) {
15 for (int64_t i = 0; i < arr.size(); i++) {
16 bool check = 0;
17 for (int64_t j = 0; j < arr.size() - i - 1; j++) {
18 if (arr[j] > arr[j + 1]) {
19 std::swap(arr[j], arr[j + 1]);
20 check = 1;
21 }
22 }
23 if (!check) {
24 break;
25 }
26 }
27}
28
29#endif