#include <iostream>
void BubbleSort(int *array, int n) {
bool swapped = true;
int j = 0;
int temp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; ++i) {
if (array[i] > array[i + 1]) {
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
swapped = true;
}
}
}
}
Bubble Sort
Use Bubble Sort Algorithm
1 Comments
BenjaminBeichler 4/6/2022, 5:45:59 AMβ’
0This snippet is no C++, it is pure C , with the exception that it includes iostream which is not used. Bubblesort should be implemented on std:: methods and not on raw pointers.
Add Comment
Log in to add a comment