Here is an implementation of BubbleSort.
void BubbleSort(int a[], int n) {
for (int i = n-1; i > 0; --i) {
for (int j = 0; j < i; ++j) {
if (a[j + 1] < a[j])
std::swap(a[j], a[j + 1]);...
Type: Posts; User: iMalc
Here is an implementation of BubbleSort.
void BubbleSort(int a[], int n) {
for (int i = n-1; i > 0; --i) {
for (int j = 0; j < i; ++j) {
if (a[j + 1] < a[j])
std::swap(a[j], a[j + 1]);...
Any time your code is about to compare two items you'll need to increment the count, much like you are in your "bubbleSort" function.
But you have a more pressing problem to solve first. How do...
That's not bubble sort. Bubble Sort only swaps adjacent items and as such an item gradually moves over until it is in place. Since you're not swapping adjacent items, it's actually just moving the...