Hi,
It's not working because the for loop is called only once. Actually, as seen
here, on Wikipedia[
^], the bubblesort algorithm should run that loop until the array is sorted.
Do you should add a
do{...}while(array_not_sorted);
and that
array_not_sorted
is a boolean variable. If in the last iteration you've swapped some elements, the array is not sorted and the do loop should be re-executed, otherwise the array is sorted and both the do and for loop should end. Try to write the code by yourself now ;-)
Hope this helps
LG