Skip to content

Instantly share code, notes, and snippets.

@irchimi
Created June 24, 2020 20:17
Show Gist options
  • Save irchimi/0441723040922244a21b6128589b375c to your computer and use it in GitHub Desktop.
Save irchimi/0441723040922244a21b6128589b375c to your computer and use it in GitHub Desktop.
BubbleSort in C++
static void Swap(int& x, int& y) {
int swap = x;
x = y;
y = swap;
}
static void BubbleSort(int arr[], int length) {
for (int i = 0; i < length - 1; i++) {
for (int l = i + 1; l < length; l++) {
if (arr[i] < arr[l]) {
Swap(arr[i], arr[l]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment