Java Reference
In-Depth Information
52 {
53 if (first[iFirst] < second[iSecond])
54 {
55 a[j] = first[iFirst];
56 iFirst++;
57 }
58 else
59 {
60 a[j] = second[iSecond];
61 iSecond++;
62 }
63 j++;
64 }
65
66// Note that only one of the two calls to arraycopy below
67// copies entries
68
69// Copy any remaining entries of the first array
70 System.arraycopy(first, iFirst, a, j,
first.length - iFirst);
71
72// Copy any remaining entries of the second half
73 System.arraycopy(second, iSecond, a, j,
second.length - iSecond);
74 }
75
76 private int [] a;
77 }
641
642
ch14/mergesort/MergeSortDemo.java
1 import java.util.Arrays;
1
1 /**
2 This program demonstrates the merge sort algorithm by
3 sorting an array that is filled with random numbers.
4 */
5 public class MergeSortDemo
6 {
7 public static void main(String[] args)
8 {
Search WWH ::




Custom Search