Skip to content

Instantly share code, notes, and snippets.

@shivajichalise
Created March 23, 2022 03:24
Show Gist options
  • Save shivajichalise/8cd0fc1172c27d38961470f3ba947abf to your computer and use it in GitHub Desktop.
Save shivajichalise/8cd0fc1172c27d38961470f3ba947abf to your computer and use it in GitHub Desktop.
Bubble Sort implementation in C++
#include <iostream>
using namespace std;
#define MAX 10
void bubbleSort(int arr[]) {
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < (MAX - i - 1); j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main() {
int arr[MAX] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
bubbleSort(arr);
for (int i = 0; i < MAX; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment