Length 1 return int first new intalength 2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while (j > 0 && a[j - 1] > next) { a[j] = a[j - 1]; j- - ; } a[j] = next; } } (3) Merge Sort public class MergeSorter { private int a; public MergeSorter(int anArray) { a = anArray; } public void sort() { if (a.length <= 1) return; int first = new int[a.length / 2]; int second = new int[a.length - first.length]; for (int i = 0; i < first.length; i++) { first[i] = a[i]; } for (int i = 0; i < second.length; i++) { second[i] = a[first.length + i]; } MergeSorter firstSorter = new MergeSorter(first); MergeSorter secondSorter = new MergeSorter(second); firstSorter.sort(); secondSorter.sort(); merge(first, second); } private void merge(int first, int second)...
View Full Document

This essay was uploaded on 03/30/2014 for the course HEALTH 101 taught by Professor Ayman during the Spring '14 term at Saudi Electronic University.

Ask a homework question - tutors are online