From what I see, the swapping works ok. Your problem is, that the inner part of the while
cycle will never repeat more than once, because of the way you set Done
to true
at the end. This way, only the position of the smallest element in the array is determined correctly.
If you want it to perform full bubble sort, I'd suggest exchanging the outer while
cycle for a for
cycle, like this
for (int y = 0; y < Bub.length - 1; y++) {
for (int x = 0; x < Bub.length - 1; x++) {
// do stuff
}
}
or if you want to keep the while
cycle, you should set up the ending condition correctly, as in
if ( *everything is sorted* ) {
Done = true;
}