Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent components and swaps them if they are in the wrong order. More efficient algorithms such as timsort, or merge sort are used by the sorting library build into popular programming languages such as Python and Java.

The only significant advantage that bubble sort has over most other algorithms, even quicksort, but not insertion sort, is that the ability to detect that the list is sorted efficiently is build into the algorithm. Therefore, bubble sort is not a practical sorting algorithm.

```
//
// C++ implementation of bubble sort
//
// The All â–²lgorithms Project
//
// https://allalgorithms.com/sorting
// https://github.com/allalgorithms/cpp
//
// Contributed by: Carlos Abraham Hernandez
// Github: @abranhe
//
#include <iostream>
// Swap elements
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
// Implement bubble sort
void bubble_sort(int arr[], size_t n)
{
for (size_t i = 0; i < n - 1; i++)
{
// last i elements are already in place
for (size_t j = 0; j < n-i-1; j++)
{
if (arr[j] > arr[j + 1])
{
swap(&arr[j], &arr[j + 1]);
}
}
}
}
// A utility function to print an array of size n
void print_array(int arr[], int n)
{
for (size_t i = 0; i < n; i++)
{
std::cout << arr[i] << " ";
}
std::cout << std::endl;
}
int main()
{
int arr[] = {46, 24, 33, 10, 2, 81, 50};
int n = sizeof(arr)/sizeof(arr[0]);
std::cout << "Unsorted array:" << std::endl;
print_array(arr, n);
bubble_sort(arr, n);
std::cout << "Sorted array:" << std::endl;
print_array(arr, n);
return 0;
}
```