Menu

[solved]-Using Sortsjava Codebase Change Method Names Foo Goo Moo Boo Poo Names Indicate Type Compa Q39049891

Using Sorts.java as a codebase, change the method names  foo goo moo boo poo   such that their namesindicate the type of comparison sort they implement.

Example: Classmate Edith Foogooman changed (renamed) foo() tobubbleSort().

In addition, in the method comment block for each method,briefly explain how you decided to give the method its newname.

Example: Classmate Zelmo Z. Zeroman wrote the following methodcomment block for method foo().

/* * foo() was renamed bubbleSort() because I guessed * that the code was an implementation of bubble sort. */

Note: Zelmo lost almost an improper-fraction of a point for hisbubbleSort() method comment block.

Sorts.java code :

/* * This Java application provides implementions for numerous * comparison sort algorithms. * * @creator gdt * @created 02018.10.18 * @updated 02019.03.07 morphed the assignment */public class Sorts { private static int[][] arrays = { { 3, 4, 1, 7, 2, 5, 9, 12, 6, 15 }, { 12, 6, 15, 9, 5, 2, 7, 1, 4, 3 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }, }; private static int[] copy; private static int[] a; private static int ncompares; private static int nswaps; public static void main(String[] argv) { for (int i = 0; i < arrays.length; i++) doit(i); counting_sort(); } private static void doit(int idx) { a = arrays[idx]; A(“foo”, true); foo(); A(“foo”, false); A(“goo”, true); goo(); A(“goo”, false); A(“moo”, true); moo(); A(“moo”, false); A(“boo”, true); boo(); A(“boo”, false); A(“poo”, true); poo(0, a.length-1); A(“poo”, false); } private static void A(String sort, boolean begin) { if (begin) { copy = new int[a.length]; System.arraycopy(a, 0, copy, 0, a.length); System.out.println(“beginning ” + sort + “…”); ncompares = nswaps = 0; A(); } else { System.out.println(“ending ” + sort + “…”); System.out.println(“*** #compares: “+ncompares+”; #swaps: “+nswaps); A(); System.arraycopy(copy, 0, a, 0, copy.length); } } private static void A() { for (int i = 0; i < a.length; i++) System.out.print(a[i] + ” “); System.out.println(); } private static boolean compare(int i1, int i2) { ncompares++; return a[i1] > a[i2]; } private static void swap(int i1, int i2) { int tmp = a[i1]; a[i1] = a[i2]; a[i2] = tmp; nswaps++; } private static void P(int i1, int i2) { System.out.print(“ta[” + i1 + “]=” + a[i1] + “; a[” + i2 + “]=” + a[i2]); } private static void foo() { int gap, i, j, n = a.length; for (gap = n/2; gap > 0; gap /= 2) { for (i = gap; i < n; i++) { for (j = i-gap; j >= 0; j -= gap) { P(j, j+gap); if (!compare(j, j+gap)) { System.out.println(); break; } swap(j, j+gap); System.out.println(” [swapped]”); } } } } private static void goo() { int end_i = a.length-1; while (end_i > 0) { int last_i = 0; for (int next_i = 0; next_i < end_i; next_i++) { P(next_i, next_i+1); if (compare(next_i, next_i+1)) { swap(next_i, next_i+1); System.out.println(” [swapped]”); last_i = next_i; } else System.out.println(); } end_i = last_i; } } private static void moo() { int cur_i, limit, small_i, next_i, n = a.length; for (cur_i = 0, limit = n-1; cur_i < limit; cur_i++) { small_i = cur_i; for (next_i = cur_i+1; next_i < n; next_i++) { P(small_i, next_i); System.out.println(); if (compare(small_i, next_i)) small_i = next_i; } if (small_i != cur_i) { swap(small_i, cur_i); System.out.println(” [swapped]”); } } } private static void boo() { int cur_i, limit, next_i, n = a.length; for (cur_i = 0, limit = n-1; cur_i < limit; cur_i++) { for (next_i = cur_i+1; next_i < n; next_i++) { P(cur_i, next_i); if (compare(cur_i, next_i)) { swap(cur_i, next_i); System.out.println(” [swapped]”); } else System.out.println(); } } } /* * poo() logic copied from “The C Programming Language” * by Kernighan and Ritchie. */ private static void poo(int left, int right) { int i, last; if (left >= right) return; swap(left, (left + right) / 2); last = left; for (i = left+1; i <= right; i++) { P(i, left); if (compare(i, left)) { if ((last+1) == i) ++last; else { swap(++last, i); System.out.print(” [swapped]”); } } System.out.println(); } if (left != last) swap(left, last); poo(left, last-1); poo(last+1, right); } /* * TBI (To Be Implemented…) * * Implement a Counting Sort algorithm that sorts a byte[] where * elements are in the [Byte.MIN_VALUE, Byte.MAX_VALUE] interval. * * The output for this method should match the following: * * counting_sort()… * original: 7 -128 0 7 -7 127 0 7 -128 7 42 -42 * sorted: -128 -128 -42 -7 0 0 7 7 7 7 42 127 */ static void counting_sort() { final byte[] A = { 7,-128,0,7,-7,127,0,7,-128,7,42,-42 }; System.out.println(“ncounting_sort()…”); }}

Expert Answer


Answer to Using Sorts.java as a codebase, change the method names foo goo moo boo poo such that their names indicate the type of c… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *