I am trying to sort an array of numbers from greatest to least using a bubblesort thingy but it wont work for me heres the code I have...
I am probably making a stupid mistake so dont laugh :P
Code:
#include <iostream>
using namespace std;
class sort
{
public:
void BubbleSort (int arr[], int length)
{
bool swap= true;
int temp;
for (int i = 0; swap; i++)
{
if(arr[i] > arr[i + 1])
{
temp = arr[i];
arr[i] = arr [i + 1];
arr [i+1] = temp;
swap = true;
}
}
}
};
int main()
{
sort* mySort = new sort;
int a[] = {4, 14, 5, 0, 3, 23, 7, 16, 26, 34, 45, 54, 1, 9, 6, 15, 20, 8, 32, 86};
(*mySort).BubbleSort ((a),(sizeof(a)/4));
for (int i = 0; i < (sizeof (a) / 4); i++)
{
cout << a[i] << ", ";
}
cout << "\n";
return 0;
}
Comment