A small bubbleSort program to check if Highlight.js is working properly.
(Code by the good folks at San Foundry)
//This is a C++ Program to Sort an Array using Bubble Sort
#include <iostream>
using namespace std;
void swap (int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
//Bubble Sort
void bubbleSort (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])
swap(arr[j], arr[j+1];
}
//Driver Function
int main() {
int inputArray[] = {10, 50, 21, 2, 6, 66, 802, 75, 24, 170};
int n = sizeof (inputArray) / sizeof (inputArray[0]);
bubbleSort (inputArray, n);
cout << "Sorted Array : " << endl;
for (int i = 0; i < n; ++i)
cout << inputArray[i] << " ";
return 0;
}
No comments :
Post a Comment