... combined[combinedIndex++] = data[leftIndex++]; 57        }
58        else {
59           combined[combinedIndex++] = data[rightIndex++];
60        }
61      }
62
63      // if left array is empty
64      if (leftIndex == middle2) {
65         // copy in rest of right array
66         while (rightIndex <= right) {
67            combined[combinedIndex++] = data[rightIndex++];
68         }
69      }
70      else { // right array is empty
71         // copy in rest of left array
72         while (leftIndex <= middle1) {
73            combined[combinedIndex++] = data[leftIndex++];
74         }
75      }
76
77      // copy values back into original array
78      for (int i = left; i <= right; i++) {
79         data[i] = combined[i];
80      }
81
82      // output merged array
83      System.out.printf("         %s%n%n",
84         subarrayString(data, left, right));
85   }
86
87   // method to output certain values in array
88   private static ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.