Created
March 23, 2022 03:24
-
-
Save shivajichalise/8cd0fc1172c27d38961470f3ba947abf to your computer and use it in GitHub Desktop.
Bubble Sort implementation in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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