Lab9ans - 1 private static void merge(T finalTable T leftHalf T rightHalf cfw int i = 0 index of next position to consider

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1. private static <T extends Comparable<T>> void merge(T[] finalTable, T[] leftHalf, T[] rightHalf) { int i = 0; // index of next position to consider in leftHalf int j = 0; // index of next position to consider in rightHalf int k = 0; // index of next position to fill in finalTable // While we haven't copied all of the elements from one of the halves into the finalTable: // If the next element from the left half is less than the next element from // the right half, copy the next element from the left half into the next position // in the final table. Otherwise, copy the next element from the right half into the // next position in the final table. if (leftHalf[i].compareTo(rightHalf[j]) < 0) finalTable[k++] = leftHalf[i++]; else finalTable[k++] = rightHalf[j++]; } // While there are still elements in the left half, copy these into the remaining positions // of the final table. while (i < leftHalf.length)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.

Page1 / 2

Lab9ans - 1 private static void merge(T finalTable T leftHalf T rightHalf cfw int i = 0 index of next position to consider

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online