Disappointed with his performance, Ursula has replaced Flotsam, the moray eel minion, with Floatsam, the array eel minion. Floatsam's mission, dare he choose to reject it, is to restore order in and around Atlantica.
Help Floatsam succeed by supplying the code needed to make the following bubbleSort method work.
public class Floats { public static boolean areInOrder(float a, float b) { return a >= b; } public static void swap(float[] array, int i, int j) { } public static float[] bubbleSort(float[] array) { boolean doAgain = true; int count = array.length; int i; int j; while (doAgain) { doAgain = false; // tentative for (i = 0; i < count - 1; i++) { j = i + 1; if (!Floats.areInOrder(array[i], array[j])) { doAgain = true; Floats.swap(array, i, j); } } } return array; } } class Convert { public static float[] toArrayOfFloats(String[] array) { int i = array.length; float[] arrayOfFloats = new float[i]; while (--i >= 0) { arrayOfFloats[i] = Float.valueOf(array[i]); } return arrayOfFloats; } public static String toString(float[] array) { String s = ""; int n = array.length; for (int i = 0; i < n; i++) { if (i > 0) { s += " "; } s += array[i]; } return s; } } class BubbleSort { public static float[] work(String[] strings) { float[] array = Convert.toArrayOfFloats(strings); return Floats.bubbleSort(array); } public static void main(String[] args) { float[] sortedArray = BubbleSort.work(args); String s = Convert.toString(sortedArray); System.out.println(s); } }
Floats = { areInOrder: function(a, b) { return a >= b; }, swap: function(array, i, j) { }, bubbleSort: function(array) { var doAgain = true; var count = array.length; var i; var j; while (doAgain) { doAgain = false; // tentative for (i = 0; i < count - 1; i++) { j = i + 1; if (!Floats.areInOrder(array[i], array[j])) { doAgain = true; Floats.swap(array, i, j); } } } return array; } } Convert = { toArrayOfFloats: function(array) { var i = array.length; var arrayOfFloats = []; while (--i >= 0) { arrayOfFloats[i] = parseFloat(array[i]); } return arrayOfFloats; }, toString: function(array) { s = ""; var n = array.length; for (var i = 0; i < n; i++) { if (i > 0) { s += ", "; } s += array[i]; } return s; } } BubbleSort = { work: function(strings) { array = Convert.toArrayOfFloats(strings); return Floats.bubbleSort(array); }, main: function(args) { var sortedArray = BubbleSort.work(args); var s = Convert.toString(sortedArray); console.log(s); } }