a little help with bubble sort
Hi all, i did a search on google with bubble sort to read up on the algorithm and it sounds easy enough but i just have a question on it regarding the swapping of numbers in the arrays..
Code:
for ( j = 1; j <= 4; j++ )
for( i = 0; i <= 3; i++ )
if ( a[ i ] > a[ i + 1 ] ) {
hold = a[ i ];
a[ i ] = a[ i + 1 ];
a[ i + 1 ] = hold;
}
if i have say 5 numbers 7, 19, 10, 5, 89
after the first pass 7 gets compared to 19 and since its false it stays.
so then it does a second pass? and compare 19 with 10 which is true.. so
hold = 19;
19 = 10;
10=hold;
so at this point in time do the array values change? so 19 and 10 get swapped around? then a 3rd pass begins comparing 19 and 5?