check the following code public class MergeSort { // The mergeSort method returns a sorted
Fantastic news! We've Found the answer you've been seeking!
Question:
check the following code public class MergeSort { // The mergeSort method returns a sorted copy of the // String objects contained in the String array data. /** * Sorts the String objects using the merge sort algorithm. * * @param data the String objects to be sorted * @return the String objects sorted in ascending order */ public static String[] mergeSort(String[] data) { if (data.length > 1) { String[] left = new String[data.length / 2]; String[] right = new String[data.length - left.length]; System.arraycopy(data, 0, left, 0, left.length); System.arraycopy(data, left.length, right, 0, right.length); left = mergeSort(left); right = mergeSort(right); return merge(left, right); } else { return data; } } /** * The merge method accepts two String arrays that are assumed * to be sorted in ascending order. The method will return a * sorted array of String objects containing all String objects * from the two input collections. * * @param left a sorted collection of String objects * @param right a sorted collection of String objects * @return a sorted collection of String objects */ public static String[] merge(String[] left, String[] right) { String[] data = new String[left.length + right.length]; int lIndex = 0; int rIndex = 0; for (int i=0; i
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date: