Bubblesort Help~~

int main()
{
using namespace std;
int a[] = {9, 99,1,44,6,4};

bubblesort(a, 6 );
for (int i=0; i<6; i++)
{
cout << a[i] << " ";
}
cout << endl;
return 0;
}

void bubblesort(int arr[], int length)
{
// Bubble largest number toward the right
for (int i = length-1; i > 0; i--)//can you explain this logic to me??
for (int j = 0; j < i; j++)//can you explain this to me??
if (arr[j] > arr[j+1])//can you explain this to me???
{
// Swap the numbers
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
//can you pls explain the logic to me thank you!
Last edited on
Do you understand how a bubble sort works?
@kbw by the loop the array will swap the position from high to low this is what I know...
Any one can figure up for me what the loops mean??
Topic archived. No new replies allowed.