Merge Sorting by sorting algorithm (JAVA)
Merge Sorting uses recursive and divide-and-conquer technologies to divide data sequences into smaller half-child tables, and then sort the half-child tables, finally, we use recursive steps to merge the prepared semi-subtables into an ever-increasing ordered sequence. The merging and sorting involves two steps: 1) Partitioning Table 2) merge a semi-subtable. first, we will discuss the merge algorithm. The merge algorithm puts a series of data into a vector and the index range is [first, last]. this sequence consists of two sub-tables with good sorting order. The index midpoint (mid) is used as the dividing line. The following is a sequence, in a sequence such as 48, it is divided into two subsequences: 7, 10, 19, 25, and 12, 17, and 48. The next step is to use the merge algorithm: compare v [indexA] = 7 and v [indexB] = 12. Extract the smaller v [indexA] and put it in the temporary vector tempArray. Then add Step 1 to indexA: compare v [indexA] = 10 and v [indexB] = 12, place the smaller 10 to the Temporary Variable tempArray, and then indexA ++; Step 3: compare v [indexA] = 19 and v [indexB] = 12, store the smaller 12 to the Temporary Variable tempArray, and then indexB ++; Step 4 to Step 7: compare and store the data according to the above rules. The last step is to add the remaining items in sub-Table B to the temporary vector tempArray and then sort the values in the temporary variables according to the index position, copy back to vector v to complete the Merge Sorting of vector v java code implementation: All functions share a temporary array temp, each time a new temporary array overhead is too large
Package org. conan. myhadoop. mr; import java. util. arrays; public class MergeSort {public static int [] sort (int [] array, int low, int high, int [] temp) {int mid = (low + high) /2; if (low