public static void bubble( int a[] )
{
boolean done = false;
int temp;
for( int forwardPass = 1; forwardPass < N && !done; forwardPass++ )
{
done = true;
for( int i = 0; i < N - forwardPass; i++ )
{
if( a[ i ] > a[ i + 1 ] )
{
temp = a[ i ];
a[ i ] = a[ i + 1 ];
a[ i + 1 ] = temp;
done = false;
}
}
}
}
Please don't give me the answer but help walk me through it.
This is the code that makes the bubble sort keep making forward passes though the array until done = true (all the values in the array are sorted in a lowest to highest value order).
I am confused to hell as to how to make the sort make a forward pass and at the end make a backward pass and then forward again until all the values are in order.
Basically I'm trying to come up with the best algorithm of sorting to sort in the least amount of time using a bubble sort method (the one list above).