Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double[] bubble(double[] list)
- {
- double temp;
- boolean changed = false;
- do
- {
- changed = false; // Resets to false every time
- for(int j = 0; j < list.length - 1; j++) // Minus one because if uses plus one to look at next
- if(list[j] > list[j + 1]) // If next value is higher
- {
- temp = list[j]; // Shift value into temporary spot
- list[j] = list[j + 1]; // Shift higher value into value (i)
- list[j + 1] = temp; // Shift temp into higher value (swap)
- changed = true;
- }
- } while(changed); // Stop when there's no change
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment