void BubbleSort()
{
srand(time(0)); // seed for random num generator
constint n = 10;
int arr[n]; // create array of size n
// fill array with random numbers
for(int i=0; i<n; i++)
{
arr[i] = 1 + rand()%100;
}
bool sorted;
for(int i=0; i<n; i++)
{
sorted = true; // at every pass, array has potential of being sorted
for(int j = 0; j < n-i-1; j++)
{
if(arr[j]>arr[j+1])
{
swap(arr[j], arr[j+1]);
sorted = false; // if a swap was made, array was not sorted
}
}
if(sorted) // if no swaps were made, array was sorted, so break
break;
}
for(int i=0; i<n-1; i++)
assert(arr[i]<arr[i+1]); // this assertion fails every time, even though printing the number I can see that they are sorted.
}