This C++ Program implements Bubble Sort Algorithm.

The program has an input array of size 10 initialized with 10 values. This returns the array in non decreasing order using Bubble Sort algorithm.

Here is source code of the C++ Program to Implement Bubble Sort. The C++ program is successfully compiled and run on g++-4.3.2 on a Linux system. The program output is also shown below.

`//This is a C++ Program to Sort an Array using Bubble Sort`

`#include <iostream>`

using namespace std;

`//Bubble Sort`

void bubble_sort (int arr[], int n)

`{`

for (int i = 0; i < n; ++i)

for (int j = 0; j < n - i - 1; ++j)

if (arr[j] > arr[j + 1])

`{`

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

`}`

`}`

`//Driver Function`

int main()

`{`

int input_ar[] = {10, 50, 21, 2, 6, 66, 802, 75, 24, 170};

int n = sizeof (input_ar) / sizeof (input_ar[0]);

bubble_sort (input_ar, n);

cout << "Sorted Array : " << endl;

for (int i = 0; i < n; ++i)

cout << input_ar[i] << " ";

return 0;

`}`

Output :

$ g++ BubbleSort.cpp $ ./a.out Sorted Array : 2 6 10 21 24 50 66 75 170 802

**Sanfoundry Global Education & Learning Series – 1000 C++ Programs.**

Here’s the list of Best Reference Books in C++ Programming, Data Structures and Algorithms.